嗨,我想保存从imagesc(magic(3))
生成的图像,确切的彩虹表示,是否可能?
感谢。
这个问题可能看似重复,但事实并非如此。我在这个网站上查看了类似问题的解决方案,但它并不能让我满意。 我查看了Matlab帮助中心,我得到的答案就是这个,在http://goo.gl/p907wR的底部
答案 0 :(得分:14)
要将数字保存为文件(无论如何创建),应该:
saveas(figureHandle,'filename','format')
其中figureHandle可以是gcf
句柄,这意味着:获取当前数字。
正如讨论所指出的,如果有人不想显示刻度,那么此人可以添加:
set(gca,'XTick',[])
set(gca,'YTick',[])
其中gca是当前轴的句柄,就像gcf
一样。如果您有多个轴,请不要忘记“处理手柄”。它们会在您创建它们时返回给您,即:
hFig = figure(pairValuedProperties); % Create and get the figure handle
hAxes1 = suplot(2,1,1,pairValuedProperties); % Create and get the upper axes handle
hAxes2 = suplot(2,1,2,pairValuedProperties); % Create and get the bottom axes handle
其中pair值是以下语法声明的figure或axes属性:
'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,…
以下是有关Figure和Axes Properties以及saveas method的matlab文档。
示例:
使用以下代码保存图像:
figure
imagesc(magic(3))
set(gca,'XTick',[]) % Remove the ticks in the x axis!
set(gca,'YTick',[]) % Remove the ticks in the y axis
set(gca,'Position',[0 0 1 1]) % Make the axes occupy the hole figure
saveas(gcf,'Figure','png')
答案 1 :(得分:4)
您可以使用:
print -djpeg99 'foo.jpg'
这将根据需要将其保存为“foo.jpg”。
答案 2 :(得分:2)
您可以使用以下代码
imagesc(A);
%%saving the image
hgexport(gcf, 'figure1.jpg', hgexport('factorystyle'), 'Format', 'jpeg');
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4 4]);
print -djpeg filename.jpg -r10
这里A将是您将拥有图像的矩阵。图像将以filename.jpg的形式保存在目录中。