for loop within for loop
显示 更早的评论
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.
采纳的回答
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 个评论
thank you for your answer but it still doesn't work. subplot should go upto subplot(1,4,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.
shouldn't there be anything inside the second loop? :)
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.
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
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!
THANK YOU SO MUCH!! :D
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!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)


