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
ME 2019년 11월 4일

2 개 추천

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
Hinna Ahmed 2019년 11월 4일
Capture.PNG
Hinna Ahmed
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
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
Hinna Ahmed 2019년 11월 4일
shouldn't there be anything inside the second loop? :)
ME
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
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
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
Hinna Ahmed 2019년 11월 4일
Capture.PNG
Hinna Ahmed
Hinna Ahmed 2019년 11월 4일
편집: Hinna Ahmed 2019년 11월 4일
I am sorry, that I didn't state it in the initial question
ME
ME 2019년 11월 4일
편집: ME 2019년 11월 4일
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
Hinna Ahmed 2019년 11월 4일
THANK YOU SO MUCH!! :D
ME
ME 2019년 11월 4일
No problem, happy to help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2019년 11월 4일

댓글:

ME
2019년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by