How to construct a loop that changes matrix dimensions?
6 ビュー (過去 30 日間)
古いコメントを表示
So, I've created a 10x10 matrix using a for loop. But now, using the same formula for each component that I had inside the loop, I need to make another loop that calculates new matrices with other 9 dimensions (10x100, 100x100, 1000x10, and so on.) I had no idea how to do this first loop withoit initializing the matrix with a known size, so now I'm stuck as to how to keep going. Any help/tips would be appreciated, I'm very new to MATLAB
2 件のコメント
Matt J
2021 年 1 月 27 日
I had no idea how to do this first loop withoit initializing the matrix with a known size
You should do this all the time. Maybe if you post your code, we could see why you think doing so creates difficulties..
回答 (1 件)
Matt J
2021 年 1 月 28 日
For example,
I={2,4,6};
J={3,5,7};
Matrices=cell(3,3);
for m=1:numel(I)
for n=1:numel(J)
Matrices{m,n}=(1:I{m})./(1:J{n}).';
end
end
Matrices
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!