How can I set subplot size in MATLAB figure?

前端 未结 4 1114
余生分开走
余生分开走 2021-02-04 16:11

I often need to plot 10 images together, but using this code results in small images :

img = rand(400,600); 
for i=1:10
 subplot(2,5,i); 
 imshow(img); 
 title(         


        
4条回答
  •  借酒劲吻你
    2021-02-04 17:07

    Based on the answer of @brechmos, when your subplot number is more than 10 subplot, then his code will trigger a error.

     % calculate the row and column of the subplot
     row = floor( ii/(ncols+1) ) + 1
     col = mod( ii-1, ncols ) + 1
    

    e.g. 4X5 cells, then subplot 11 will be wrongly interpreted as (2, 1), but not (3,1).

    Replace it with the code below can fix it:

    % calculate current row and column of the subplot
    row = floor( (i-0.5)/ncols ) + 1;
    col = mod(i-(row-1)*ncols, ncols+1); 
    

提交回复
热议问题