Subplots within for loops

221 Ansichten (letzte 30 Tage)
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis am 2 Okt. 2017
Kommentiert: Cedric am 3 Okt. 2017
Hi all,
I can't seem to find a solution for this simple problem:
I have a for loop with an output of 8 plots. I would like to group them as they come out in 2 subplots of 4. How can I do this?
KR,
KMT.

Akzeptierte Antwort

Cedric
Cedric am 2 Okt. 2017
Bearbeitet: Cedric am 2 Okt. 2017
figure() ;
for plotId = 1 : 4
subplot(2, 2, plotId) ;
plot(x{plotId}, y{plotId}) ;
end
figure() ;
for plotId = 1 : 4
subplot(2, 2, plotId) ;
plot(x{plotId+4}, y{plotId+4}) ;
end
or in one loop, but it adds some complexity that may not be that useful:
for plotId = 1 : 8
if ~mod(plotId-1, 4)
figure() ;
end
subplot(2, 2, mod(plotId-1, 4)+1) ;
plot(x{plotId}, y{plotId}) ;
end
Finally, if you wanted to define your own axes to avoid all the space left by SUBPLOT and fit your 8 plots in one figure, you could do it as illustrated in my answer here:
  4 Kommentare
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis am 2 Okt. 2017
Very elegant! Thank you for your answer, works very well
Cedric
Cedric am 3 Okt. 2017
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by