保存 Matlab 图而不绘制它,然后在 VISIBLE 状态下打开它

Save Matlab figure without plotting it and afterwards open it in VISIBLE state

我在这里问了同样的问题:Save Matlab figure without plotting it?

但是上面给出的解决方案存在的问题是保存后的图形无法在可见状态下双击打开。看起来 savefig 命令保存可见状态。与 saveas 相同。

h=figure;
set(h,'Visible','off');
savefig('TestExample.fig');

b=openfig('TestExample.fig');

通过这个命令我可以看到图形,但我只是想双击查看它:

set(b,'Visible','on');

documentation 似乎阐明了这个问题:

Create a surface plot and make the figure invisible. Then, save the figure as a MATLAB figure file. Close the invisible figure.

surf(peaks)
set(gcf,'Visible','off')
savefig('MySavedPlot.fig')
close(gcf)

Open the saved figure and make it visible on the screen.

openfig('MySavedPlot.fig','visible')

...但是,遗憾的是,当您使用双击界面时,它可能无法正常工作。该问题也已在 here 中讨论,并且需要更改 openfig 的默认行为。它可以通过编辑内置函数来实现,但是有点脏。

Jesse Hopkins 在下面的评论中提出了另一种解决方法:

Set the ResizeFcn on the figure to renable visibility. According to Matlab documentation, and in practice, ResizeFcn is called when figure is created: set(h,'ResizeFcn','set(gcf,''visible'',''on'')');

好的是,此变通方法应该适用于设置负载 any 属性 您可能想在正在加载的图形句柄上设置。

对我来说最好的解决方案是(感谢链接,):

figure('Visible','off')
set(gcf,'Visible','off','CreateFcn','set(gcf,''Visible'',''on'')')
savefig('Test.fig')
close

数字不弹出,我只能通过双击打开它们。