How to make subplot go down the column and not across the row in the first instance?

58 ビュー (過去 30 日間)
jj
jj 2013 年 6 月 22 日
編集済み: Romain 2016 年 10 月 11 日
Hi everyone,
I have a question that I can't seem to figure out. So, I am using subplots to combine two matrices I wish to combine in one diagram. Each matrix has 5 variables that will be plotted. Specifically, I am trying to combine them such that they appear in a 5 rows by 2 columns diagram. I am able to do that. But, when using subplot to combine these 10 figures into the same diagram, Matlab goes across the columns before heading down to the second row when plotting these figures. Is there anyway to make Matlab fill up the first column first before going onto the second column, without specifying the 10 subplots individually (as they are all in 2 matrices)?
Thanks! :)
  1 件のコメント
Jan
Jan 2013 年 6 月 22 日
SUBPLOT does not combine "figures" to a "diagram", but "diagrams" (better "axes") on a "figure". What does "they are all in two matrices" mean?

サインインしてコメントする。

回答 (3 件)

Jan
Jan 2013 年 6 月 22 日
編集済み: Jan 2013 年 6 月 22 日
index = reshape(1:10, 2, 5).';
for i = 1:10
subplot(5, 2, index(i));
text(0.5, 0.5, sprintf('%d', i));
end

Matt J
Matt J 2013 年 6 月 22 日
Why not just change the order of the images instead of trying to change the order of the figure plotting. For example, suppose your images exist in a 5x2 cell array. Then just transpose the array,
images=images.';
for i=1:10
subplot(5,2,i)
imshow(images{i})
end

Romain
Romain 2016 年 10 月 11 日
編集済み: Romain 2016 年 10 月 11 日
Since I faced the same issue today here an easy solution. I tweaked the subplot script so that it fills the columns first and it works quite well. Go to lines 291-292 and change them as
%row = (nRows - 1) - fix((plotId - 1) / nCols);
%col = rem(plotId - 1, nCols);
% lines to change:
col = (nCols - 1) - ((nCols - 1) - fix((plotId - 1) / nRows));
row = (nRows - 1) - (rem(plotId - 1, nRows));

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by