How to create a new matrix with a for loop?
4 ビュー (過去 30 日間)
古いコメントを表示
Hello friends,
I am a newbie. I have problem.
I have 20 (1x100) different named vectors. I want to combine these vectors to create a 20x100 matrix with a for loop.
There are the examples of vectors.
namelist=["First","B","New"]
First = [1:100]
B = [1:2:200]
New = [4:4:400]
I want to create a new database(20x100) with "First, B , New" vectors with a for loop.
for i = 1: length(namelist)
new_database(i,1:end) = namelist{i}
end
But, when I want to try this I saw "The end operator must be used within an array index expression." error.
I know I can do same thing with this code
new_database= [First;B;New]
but i want to do this with a for loop.
Would you help me how can fix this error? or Would you explain me how can do this?
0 件のコメント
採用された回答
KSSV
2021 年 9 月 15 日
You should not create individual arrays like that. You should proceed something like this
iwant = zeros(3,100) ;
iwant(i,:) = 1:1:100 ;
iwant(2,:) = 2:2:200 ;
iwant(3,:) = 4:4:400 ;
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!