Plot multiple figures in background

独自空忆成欢 提交于 2020-01-16 01:01:14

问题


I have a MATLAB code that plots multiple figures at the same time. The general trick to achieve the same is to call figure(figHandle) and then make a call to plot, for e.g.

figure(h1);
plot(...args...);
figure(h2);
plot(...args...);

However, I want to do this plotting without bringing figures into foreground everytime I make a call to figure(figHandle). All I want to do is to plot multiple figures simultaneously without bringing them into visibility and export them to an excel sheet (I have figured out exporting to excel sheet part) in the end.

The problem is there are too many figures (around 100) and I have to manually close them down. All I want in the end is an excel sheet with figures exported.

Thanks.


回答1:


If the problem is to close all the figures you can just use the command close all.




回答2:


I agree with the solution of mola (+1). However, if you did for some reason wish to keep the figures available after exporting to excel, but don't want them visible on screen, just set the visible property of the figure to off when creating it:

fig1 = figure('visible', 'off')

And if you suddenly decide you need to see it:

set(fig1, 'visible', 'on')

EDIT: It just occurred to me, that if you don't care about ever seeing the figures in matlab, then you should definitely be setting the visible property of the figure to off when you create it. This should significantly speed up the runtime of your code. For example:

x = (1:100)';
tic
for i = 1:1:10
    fig1 = figure('visible', 'off');
    plot(x);
end
close all
toc

takes 0.27 seconds to run on my machine, but if I switch 'off' to 'on', the runtime increases to 0.65 seconds.




回答3:


Assign figure handles like

fig1 = figure

run

close figure1

to close figure1 when you’re through with it. Also, if you want to plot multiple things in one figure by tiling, use the subplot function.

When I run Matlab from terminal, and I want to generate a bunch of plots to be saved in an html file, I run this function I wrote, passing the script of interest as an argument, and simply set it and forget it:

function directoryOutput = cliPub(scriptName)
clc;
close all;
fprintf('Publishing...\n\n');
directoryOutput = publish(fullfile(pwd, scriptName), 'figureSnapMethod', 'getframe', 'useNewFigure', false);
close all;


来源:https://stackoverflow.com/questions/12449896/plot-multiple-figures-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!