How to store data in a nested for loop?

1 回表示 (過去 30 日間)
Mr. 206
Mr. 206 2018 年 11 月 14 日
コメント済み: madhan ravi 2018 年 11 月 14 日
This is my skeleton Code:
c = 0
for J = 1: 1 : 12
c = c+1;
.
.
.
for delta = 1: 1 : 10
.
.
.
A (c) =
B (c) =
C (c) =
D (c) =
end
end
Here the output of A, B, C, D are (12 by 1) column vectors. In my case i can only store one 12 by 1 column vector A for delta = 10. I want to store all the A vectors for delta 1 to 10 and store side by side so that i can get a 12 by 10 matrix.
Same thing implies for B,C,D also.
How can i store the data in this pattern?

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 14 日
編集済み: madhan ravi 2018 年 11 月 14 日
A=cell(12,10); %pre-allocation for speed and efficiency
B=cell(12,10);
C=cell(12,10);
D=cell(12,10);
for J = 1:12
for delta = 1:10
A{c,delta} =
B{c,delta} =
C{c,delta} =
D{c,delta} =
end
end
see { } which stores the values as cell , to view the values simply do
celldisp(A)
  12 件のコメント
Mr. 206
Mr. 206 2018 年 11 月 14 日
May be due to something inside my code it is not acting as expected.
To me your logic looks good. I am accpeting the Answer.
Again thanks for your help.
madhan ravi
madhan ravi 2018 年 11 月 14 日
Anytime :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by