【问题标题】:How to set axis for multiple subplots of pictures in Matlab如何在Matlab中为图片的多个子图设置轴
【发布时间】:2014-01-20 20:40:19
【问题描述】:
clear all; close all; clc;
A = im2double(imread('cameraman.jpg'));
figure(1)
imshow(A)

C = chunking(A,400,400) % separates picture;
[m n] = size(C);
k = 1;
figure(1)
for i = 1:m
    for j = 1:n
        subplot(m,n,k)
        imshow(C{i,j})
        axis off;
        k = k + 1;

    end
end

所以在上面的代码中,我试图将图片分成 400x400 像素块。由于图像不是 400x400 的倍数,因此它将在边框和右下角具有不相等的部分(仍然是方形图像)。但是,当我使用 subplot 时,它会将最后一个块的大小调整为相同的大小。我尝试使用 get 和 set position,但它给出了每个子图的宽度和高度是相同的?![在此处输入图像描述][1]

http://imgur.com/2VUYZr1

【问题讨论】:

    标签: matlab plot matlab-figure


    【解决方案1】:

    如果要显示的像素少于 400,则需要调整坐标区的大小。您应该将句柄存储到每个子图,然后在需要更小时调整它的大小。

    您对 subplot 的调用应如下所示:

    h = subplot(m,n,k);
    num_rows = size(C{i,j}, 1);
    num_cols = size(C{i,j}, 2);
    set(h, 'units', 'pixels')
    old_axes_pos = get(h, 'position');
    new_axes_pos = old_axes_pos;
    if num_cols < 400
       new_axes_pos(3) = num_cols; % Make this axes narrower
    end
    % If the figure cannot be full height
    if num_rows < 400
       new_axes_pos(4) = num_rows;  % Make this axes shorter
       new_axes_pos(2) = old_axes_pos(2) + (400 - num_rows); % Move the bottom up
    end
    set(h, 'position', new_axes_pos) % Change the size of the figure
    

    【讨论】:

      猜你喜欢
      • 2012-10-20
      • 2016-08-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 2015-03-31
      相关资源
      最近更新 更多