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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by