how to save multiple figure without displaying

조회 수: 9 (최근 30일)
Yu Li
Yu Li 2017년 3월 2일
편집: Y. J. 2018년 7월 26일
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
Yu Li
Yu Li 2017년 3월 3일
hi; looks this is a good ideal. let me have a try! thanks! Li
John BG
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
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
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.

Walter Roberson
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

Y. J.
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')

카테고리

Help CenterFile 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!

Translated by