我不相信有一种简单的方法可以做到这一点。有两种选择:
首先,使用子图的位置部分:
>> subplot(2,5, i, [l, b, w, h])
并计算左、下、宽、高。
或者,获取返回轴的句柄:
>> h(i) = subplot(2,5,i);
然后修改轴。
>> set(h(1), 'position', [l, b, w, h] );
有许多页面将提供更多详细信息,例如,http://www.briandalessandro.com/blog/how-to-make-a-borderless-subplot-of-images-in-matlab/ http://www.briandalessandro.com/blog/how-to-make-a-borderless-subplot-of-images-in-matlab/
[update]
下面的代码更详细地说明了谁可以做您正在寻找的事情。这有点乏味。 0.95 和 0.02 只是为了提供一点填充。它们并不神奇。 :-)
另一件需要注意的事情是,我真的鼓励您使用“ii”作为索引变量(或其他变量),因为“i”被定义为 sqrt(-1)。不使用“i”和“j”作为索引变量是一个很好的约定(尤其是在 Matlab 中)。
img = rand(400,600);
figure(1);
clf();
hold on;
% Get the width and height of the figure
lbwh = get(1, 'position');
figw = lbwh(3);
figh = lbwh(4);
% Number of rows and columns of axes
ncols = 5;
nrows = 2;
% w and h of each axis in normalized units
axisw = (1 / ncols) * 0.95
axish = (1 / nrows) * 0.95
for ii=1:10
% calculate the row and column of the subplot
row = floor( ii/(ncols+1) ) + 1
col = mod( ii-1, ncols ) + 1
% calculate the left, bottom coordinate of this subplot
axisl = (axisw+0.02) * (col-1)
axisb = (axish+0.02) * (row-1)
% plot the subplot
h= subplot('position', [axisl, axisb, axisw, axish] );
imshow(img);
title(['Image ' int2str(ii)]);
pause
end
您必须使用它才能使其完全按照您的要求行事。 “帮助”是你的朋友。