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

58 次查看(过去 30 天)
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));

Community Treasure Hunt

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

Start Hunting!

Translated by