我试图用隐藏的Matlab数字进行绘图,以加快我的绘图速度:
a=1:10; b=-a;
% make invisible plot window
f = figure('visible','off');
g = figure('visible','off');
% figure makes the plot visible again
figure(f)
plot(a)
saveas(f,'newout','fig')
figure(g)
plot(b)
saveas(g,'newout2','fig')
%% load saved figures
openfig('newout.fig','new','visible')
openfig('newout2.fig','new','visible')
问题是 figure(f)命令使绘图窗口再次可见。 当我只有一个图并且没有调用图(f)时,代码绘制没有图形窗口。
答案 0 :(得分:4)
我刚刚了解到,不应该调用figure(f)
,而应该使用set:
set(0, 'currentfigure', g);
这将更改当前数字句柄而不更改其可见性。 更正后的版本按预期工作:
a=1:10; b=-a;
% make invisible plot window
f = figure('visible','off');
g = figure('visible','off');
% figure makes the plot visible again
set(0, 'currentfigure', f);
plot(a)
saveas(f,'newout','fig')
set(0, 'currentfigure', g);
plot(b)
saveas(g,'newout2','fig')
%% load saved figures
close all
openfig('newout.fig','new','visible')
openfig('newout2.fig','new','visible')
答案 1 :(得分:0)
我建议制作一个全新的情节窗口。通过这样做,你将获得两个不同的情节,正如你所说只有一个情节有效,我认为它可以工作。
答案 2 :(得分:0)
另一种解决方案是在plot
命令中引用轴(而不是在plot
之前更改当前数字):
a=1:10; b=-a;
f = figure('visible','off');
fax = gca; %// get handle to axes of figure f
g = figure('visible','off');
gax = gca; %// get handle to axes of figure g
plot(fax, a) %// plot in axes of figure f
saveas(f,'newout','fig')
plot(gax, b) %// plot in axes of figure g
saveas(g,'newout2','fig')
openfig('newout.fig','new','visible')
openfig('newout2.fig','new','visible')