For loop and subplot
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
Walter Roberson
2019 年 8 月 15 日
subplot(6,2,2*i-1)
subplot(6,2,2*i)
3 件のコメント
Walter Roberson
2019 年 8 月 15 日
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
2019 年 8 月 15 日
Use this simple scheme i created for you
Numbers in mesh indicates number of subplot
subplot(3,2,i)
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!