I have a for loop and in each loop I plot to figures. I want each pair of figure to be plotted next to each other (left and right).
I mean for i=1 I have two plots. I want one to be on the left and one on the right and so on.
I tried subplot(6,2,i); and subplot(6,2,i+1); in each loop but did not work. i=1 would plot on the first row left. i=2 would plot on the 1st row right but I wanted to plot on the second row left.

답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 15일

0 개 추천

subplot(6,2,2*i-1)
subplot(6,2,2*i)

댓글 수: 3

Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 8월 15일
Thanks. But I wanted to find a systematic way. I mean is there any structure that I can define in matlab so it can place the plot where I want?
plots_down = 6; plots_across = 2;
subplot( plots_down, plots_across, sub2ind([plots_across, plots_down], column_of_plot, row_of_plot))
For example,
%notice the 6, 2 in one place but the 2, 6 in the other case
subplot(6, 2, sub2ind([2, 6], 1, i)) %left
subplot(6, 2, sub2ind([2, 6], 2, i)) %right
This can be done more directly by using the formula for sub2ind directly, as
subplot( plots_down, plots_across, (row_of_plot-1)*plots_across + column_of_plot)
which for 2 plots across would be
subplot( plots_down, 2, (i-1) * 2 + 1) %left
subplot( plots_down, 2, (i-1) * 2 + 2) %right
and in your particular case that would optimize as
subplot(6, 2, 2*i - 1) %left
subplot(6, 2, 2*i) %right
so this is a systematic way.
darova
darova 2019년 8월 15일
Use this simple scheme i created for you
Numbers in mesh indicates number of subplot
subplot(3,2,i)
22Untitled.png

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

카테고리

질문:

2019년 8월 15일

댓글:

2019년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by