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.

 Accepted Answer

ME
ME on 4 Nov 2019
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 Comments

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? :)
ME
ME on 4 Nov 2019
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 on 4 Nov 2019
Edited: Hinna Ahmed on 4 Nov 2019
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 on 4 Nov 2019
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 on 4 Nov 2019
Edited: Hinna Ahmed on 4 Nov 2019
I am sorry, that I didn't state it in the initial question
ME
ME on 4 Nov 2019
Edited: ME on 4 Nov 2019
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
ME
ME on 4 Nov 2019
No problem, happy to help!

Sign in to comment.

More Answers (0)

Tags

Asked:

on 4 Nov 2019

Commented:

ME
on 4 Nov 2019

Community Treasure Hunt

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

Start Hunting!