How to store data in a nested for loop?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
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 件のコメント
Hi,
See using A (c) i am piling all the A values for J loop into one column (12 by1) vector. Now for delta there are 10 such kind of column vectors (12 by 1).
I just need to pile them together to get a 12 by 10 matrix. Hope i can make my point.
madhan ravi
2018 年 11 月 14 日
yes i understood your point see edited answer
Mr. 206
2018 年 11 月 14 日
celldisp(A) is not giving a 12 by 10 matrix. Rather it is giving a lot of individual numbers!
madhan ravi
2018 年 11 月 14 日
編集済み: madhan ravi
2018 年 11 月 14 日
you could do
[A{:}]
also whats your formula on right hand side it should produce 12by1 elements in an iteration
Mr. 206
2018 年 11 月 14 日
A is actually producing one number, after doing A (c) it creates a 12 by 1 column vector.
madhan ravi
2018 年 11 月 14 日
編集済み: madhan ravi
2018 年 11 月 14 日
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.
? so did you try my code?
It creates one long column vector. It is piling all the A in one column vector
madhan ravi
2018 年 11 月 14 日
can you provide the formula so i can try it out myself?
Mr. 206
2018 年 11 月 14 日
I solved the problem. Thanks for your effort.
c = 0
for J = 1: 1 : 12
c = c+1;
.
.
.
for delta = 1: 1 : 10
.
.
.
A (c,delta) =
B (c,delta) =
C (c,delta) =
D (c,delta) =
end
end
madhan ravi
2018 年 11 月 14 日
Thats exactly what my answer would also give you
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
2018 年 11 月 14 日
Anytime :)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および 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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
