how to save multiple figure without displaying
7 次查看(过去 30 天)
显示 更早的评论
I'm working on a code that repeating plot data to different figure. below is a test code:
clear
clc
for j=1:3
h1=figure(1);
x=0:0.01:1;
y=x.*j;
plot(x,y);
set(h1,'visible','off');
h2=figure(2);
x=0:0.01:1;
y=x.*j;
plot(x,y);
set(h2,'visible','off');
h3=figure(3);
x=0:0.01:1;
y=x.*j;
plot(x,y);
set(h3,'visible','off');
end
the problem is that the figure is blinking on the screen.
I read some answer in forum, such as:
f = figure('visible', 'off');
however, in my situation, I need to plot multiple figure, is there anyway to set the figure invisible since it is created? for example I want to make figure(2) invisible, the code like is:
f = figure(2, 'visible', 'off');
thanks!
Li
3 个评论
John BG
2017-3-4
Yu Li
happy to help.
there is no way to tell plot to go 'invisible' once you invoke it.
it's like telling a bullet not to leave the barrel once the pin has pierced it.
Would you please be so kind to consider marking my answer as accepted answer?
I have copied my comment as answer that you and other people in the forum may find useful.
If you mark my answer as accepted I get 4 credit points.
Thanks in advance for time and attention, awaiting answer
John BG
采纳的回答
John BG
2017-3-4
Yu Li
why don't you just save the variables, [x,y] for each plot BEFORE plotting in a .mat file?
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
更多回答(3 个)
Rik
2017-3-2
You can't combine the attributes with the number syntax at figure creation, so you'll have to use your current solution. If you try h1=figure(1);ax1=gca;set(h1,'visible','off');plot(ax1,x,y), plot(ax1,x,y) will set the figure to visible.
If you need to go for invisible, you can always do something like set(h,'OuterPosition',[-0 0 eps eps]). You will probably be stuck some of that time with the figures stealing focus, but I think it is you best bet. This will also probably mess up some of the thing you might want to do with these plots.
0 个评论
Walter Roberson
2017-3-3
fig(1) = figure(1);
ax(1) = axes('Parent', fig(1));
fig(2) = figure(2);
ax(2) = axes('Parent', fig(2));
fig(3) = figure(3);
ax(3) = axes('Parent', fig(3));
for j=1:3
x=0:0.01:1;
y=x.*j;
if j == 1
p(1) = plot(ax(1), x, y);
else
set(p(1), 'XData', x, 'YData', y);
end
x=0:0.01:1;
y=x.*j;
if j == 1
p(2) = plot(ax(2), x, y);
else
set(p(2), 'XData', x, 'YData', y);
end
x=0:0.01:1;
y=x.*j;
if j == 1
p(3) = plot(ax(3), x, y);
else
set(p(3), 'XData', x, 'YData', y);
end
drawnow();
end
0 个评论
Y. J.
2018-7-26
编辑:Y. J.
2018-7-26
Hey guys maby u can help me with my problem too... . I think it is a small addon to the code before
Im doing something like:
f(1) = figure('visible', 'off');
ax(1) = axes('Parent', f(1));
while(some condition)
load some data;
plot(ax(1),x.Torque1cNm, y.Speed1RPM,'DisplayName', N);
xlabel('Torque [cNm]');
ylabel('Speed [rpm]');
title('Torque vs Speed');
legend('-DynamicLegend');
hold all
end
saveas(f(1), 'xxxx', 'png');
(Lets assume i plot two line in that figure) The second one overwrites the first and there is no legend no grid no title or axis labeling. What im doing wrong?
Edit:
Sorry that is not the complete information. In this case it works but in my real code im opening 20 different figure and i think they overwriting each other. What can I do in this case? because i can´t write smth. like
figure(1,'visible', 'off')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!