我想要写一个Matlab函数,它可以显示一幅图像,多幅图像(即细胞阵列,矢量,矩阵),这样我就不用担心每次我用新的输入运行我的程序时,都会编写“图”、“子图”和其他复杂的Matlab机制。这也是我的项目要求之一。
以下源代码有几个问题:
如何解决这些问题?
源代码
function draw_images(image_list)
d = size(image_list);
l = length(d);
figure;
hold all
colormap(gray(256));
% vector or cell-array
if(l==2)
N = length(image_list);
[m, n] = factor_out(N);
% images may be of differenet dimensions
if(iscell(image_list))
for k=1:N
h = subplot(m,n,k);
image(image_list{k},'Parent',h);
set(gca,'xtick',[],'ytick',[])
end
% must be of same dimension
elseif(isvector(image_list))
for k=1:N
h = subplot(m,n,k);
image(image_list(k),'Parent',h);
set(gca,'xtick',[],'ytick',[])
end
end
% 3D matrix of images (!!!)
elseif(l==3)
N = d(3) ;
[m, n] = factor_out(N);
for k=1:N
I = image_list(:,:,k);
subplot(m,n,k);
imshow(I);
set(gca,'xtick',[],'ytick',[])
end
end
hold off
function [m, n] = factor_out(input_number)
sqrtt = ceil(sqrt(input_number));
m = sqrtt;
n = sqrtt;发布于 2017-07-18 12:37:25
我认为在python中没有类似于pyplot.tight-layout()的内置解决方案。然而,有几个作者编写的解决方案。我更喜欢称为紧致图的函数
还有一个关于这个问题的讨论,在Stackoverflow上叫做如何在matlab中减少子图周围的边界?。
https://stackoverflow.com/questions/45166937
复制相似问题