要将图形保存为文件(无论它是如何创建的),应该执行以下操作:
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
其中对值是按以下语法声明的图窗或轴属性:
'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,…
以下是有关 matlab 的文档Figure and 轴属性,以及关于保存方法.
Example:
使用以下代码保存图像:
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')