for loop within for loop
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Hey,
I want to make two for loops. the first for loop is when the values are j = [1:4,5:8,9:2,13:6,7:20,21:24]
because I am using this for a subplot, so when j = 1 or j=5 or j=9 or j=13 or j=17 or j=21 then i=1.
When j=2, j=6 ,j=10 , j=14 , j=18 or j=22 then i=2.
When j=3, j=7, j=11, j=15, j=19 or j=23 then i=3.
When j=4, j=8, j=12, j=16, j=20, j=24 then i=4.
採用された回答
ME
2019 年 11 月 4 日
I don't know what you want to do inside those for loops so I can't give you full code but the loops you'll want are:
for i=1:4;
for j=i:4:24;
end
end
12 件のコメント
Hinna Ahmed
2019 年 11 月 4 日

Hinna Ahmed
2019 年 11 月 4 日
thank you for your answer but it still doesn't work. subplot should go upto subplot(1,4,4).
ME
2019 年 11 月 4 日
for i=1:4;
for j=i:4:24;
end
subplot(1,4,i);
plot(...)
end
Depending on how you store your results, you may need to do your plotting commands with some (i:4:end) commands in there to miss out a bunch of zeros.
Hinna Ahmed
2019 年 11 月 4 日
shouldn't there be anything inside the second loop? :)
ME
2019 年 11 月 4 日
My assumption was that you needed to get the correct combinations of i and j for some further calculations. I was imagining that you'd fill those calculations in within the j for loop. Otherwise I can't understand what you are actually plotting.
Hinna Ahmed
2019 年 11 月 4 日
編集済み: Hinna Ahmed
2019 年 11 月 4 日
I am plotting a matrix from a table.
imagesc(t/60,F,DataTable3.Coh_time{j,1})
j is actualle the row of its location. The length of the table is 24. the first 4 rows should be plotted in a subplot together and then the next 4 rows in another subplot and so on (upto 6 plots). There should be 6 plots each containing 4 subplots. The imagesc function is actually plotting the matrix.
ME
2019 年 11 月 4 日
Well then if that's what you want then that should have been stated in your initial question!
If you could attach the data table to your question that would be extremely helpful!
Hinna Ahmed
2019 年 11 月 4 日

Hinna Ahmed
2019 年 11 月 4 日
編集済み: Hinna Ahmed
2019 年 11 月 4 日
I am sorry, that I didn't state it in the initial question
No problem, it's just that people are giving up their time to answer these questions and that is all for nothing if the questions aren't clear.
Anyway, if you want the first four rows of your cell array to be figure one, rows 5-8 in figure two and so on, then you can use:
for p=1:6
figure
for i=1:4
subplot(2,2,i)
imagesc(C{((p-1)*4)+i,1})
end
end
where p is for the six figures and i is for the four rows. I have assumed a 2x2 layout for the subplots in each figure window but if you'd prefer then all in a line then swap subplot(2,2,i) for either subplot(1,4,i) or subplot(4,1,i).
I hope this helops now!
Hinna Ahmed
2019 年 11 月 4 日
THANK YOU SO MUCH!! :D
ME
2019 年 11 月 4 日
No problem, happy to help!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
タグ
参考
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)
