在我正在编写的 MATLAB 函数中,我正在生成一个图形。执行该功能时会显示该图形。我需要将图形保存为 JPEG 图像。为此,我可以在显示图形的图形窗口中执行文件->另存为。但我想自动化这个。我尝试使用 saveas() 函数来做到这一点。问题是生成的图像是不可取的。以下是演示问题的图像,向您展示我的意思:
使用 MATLAB 图窗窗口中的 File->Save As 手动保存的 JPEG 图像:
使用 saveas() 函数保存的 JPEG 图像(请注意,绘图不太好,并且标题重叠):
这是我生成图形并使用 saveas() 将图形保存为 JPEG 的 MATLAB 函数:
function JpgSaveIssueDemo( )
figure( 1 );
t = 0:0.1:8;
subplot( 2, 2, 1 );
plot( t, sin(t) );
title( 'Plot 1 of Example to Demonstrate JPG Save Issue', 'FontSize', 18 );
subplot( 2, 2, 2 );
plot( t, sin(t) );
title( 'Plot 2 of Example to Demonstrate JPG Save Issue', 'FontSize', 18 );
subplot( 2, 2, 3 );
plot( t, sin(t) );
title( 'Plot 3 of Example to Demonstrate JPG Save Issue', 'FontSize', 18 );
subplot( 2, 2, 4 );
plot( t, sin(t) );
title( 'Plot 4 of Example to Demonstrate JPG Save Issue', 'FontSize', 18 );
saveas( gcf, 'DemoPlot', 'jpg' );
end
执行 JpgSaveIssueDemo() 时显示的图形未最大化。所以,我想如果我可以在执行 saveas()之前使用 JpgSaveIssueDemo() 中的函数调用/s 最大化它,那么保存的 JPEG 图像会很好。
所以,我在 JpgSaveIssueDemo() 的 saveas() 行之前使用了这段代码来最大化图形:
drawnow;
jFrame = get(handle(gcf),'JavaFrame');
jFrame.setMaximized(true);
然后,显示的图形被最大化。但是,结果是一样的:JPEG 图像仍然不理想地出现。
为此可以做些什么?