How can I name matrices generated by a for loop as Z1,Z2,Z3 ...etc.

1 回表示 (過去 30 日間)
Milani Tharuka
Milani Tharuka 2020 年 7 月 6 日
コメント済み: Milani Tharuka 2020 年 7 月 6 日
for (i=1:x1)
for(j=1:x2)
Z=zeros(N,M)
end
end
For example if x1=4,x2=4,N=8,M=8 I will have 16 zero matrices(8*8).All are named as z.
I need to name them as z1,z2,z3 ... etc.
Thanks for the help in advance

採用された回答

Stephan
Stephan 2020 年 7 月 6 日
編集済み: Stephan 2020 年 7 月 6 日
There are a lot of contributions (one of the best is here) which show why this way of coding is bad - use an efficient way by indexing and take advantage of the methods Matlab gives you:
N = 3;
M = 4;
x1 = 2;
x2 = 2;
Z = zeros(N,M,x1*x2)
gives you a 3D-matrix which has size x1*x2 in the third dimension
Z(:,:,1) =
0 0 0 0
0 0 0 0
0 0 0 0
Z(:,:,2) =
0 0 0 0
0 0 0 0
0 0 0 0
Z(:,:,3) =
0 0 0 0
0 0 0 0
0 0 0 0
Z(:,:,4) =
0 0 0 0
0 0 0 0
0 0 0 0
  1 件のコメント
Milani Tharuka
Milani Tharuka 2020 年 7 月 6 日
Thank you very much for your answer and for the prompt reply stephan

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by