Matlab绘制无窗口的多个数字

时间:2014-09-17 14:09:51

标签: matlab matlab-figure

我试图用隐藏的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)时,代码绘制没有图形窗口。

3 个答案:

答案 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')
相关问题