필터 지우기
필터 지우기

Having trouble with saving multiple figures as they are produced in sequence.

조회 수: 12 (최근 30일)
Owen
Owen 2024년 1월 26일
댓글: Owen 2024년 1월 30일
Hello. I'm currently having some trouble saving some figures that my script is producing from a pool of pre-collected data. Really I just need the figures in a .fig format so I can inspect them and obtain the data points in a seperate script. My script currently reads:
cycle=[200 80 40 20];
begin=[753 785 795 739];
cnum=[2 4 8 16];
for i=1:4:16
ii=(i-1)/4+1;
subplot(2,2,ii)
for j=0:3
k=i+j;
for ll=1:cnum(FREQ)
tempsin=sintrace(begin(FREQ)+cycle(FREQ)*(ll-1):begin(FREQ)+cycle(FREQ)*ll-1,k);
sinpart(1:cycle(FREQ),ll)=tempsin;
end
clear tempsin;
tempsum=sum(sinpart,2)/cnum(FREQ);
sinavg(1:cycle(FREQ),k)=tempsum;
clear tempsum sinpart;
plot(vsine(begin(FREQ):begin(FREQ)+cycle(FREQ)-1,k),sinavg(1:cycle(FREQ),k))
hold on
end
hold off
title([num2str(freq(FREQ)),'Hz, ','Mean V=',num2str(vmean(ii)),'V'])
axis([-100 100 -1.5 1.5,])
end
pause
plot(vsine(begin(FREQ):begin(FREQ)+cycle(FREQ)-1,k),sinavg(1:cycle(FREQ),k))
fig = gcf;
saveas(fig,'dddd.fig')
With my attempt at saving the figures at the bottom. l honestly feel as though there is a very simple way of going about this that I just havent considered yet.
  댓글 수: 8
Walter Roberson
Walter Roberson 2024년 1월 30일
Which line is showing the error?
PLOTNUM = PLOTNUM + 1;
filename = "dddd" + PLOTNUM + ".fig";
fig = gcf;
save(fig, filename);
Owen
Owen 2024년 1월 30일
fig = gcf declaration makes it work correctly. Thanks!

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2024년 1월 26일
You don't mention the problem, but I will say that I typically put a
drawnow
command just before saving/printing figures. I'm not sure why, but I have found that MATLAB sporadically gets confused about which figure is being saved. Using drawnow, and specifying the figure in the saveas command (as you have already done) generally works for me.
  댓글 수: 1
Owen
Owen 2024년 1월 29일
편집: Owen 2024년 1월 29일
This works to save one of my figures (usually the last one produced), but since the figures are produced in sequence and not all at once, I need a path to save all of the average graphs in sequence as they are produced to seperate .fig files. It would also help if I could find a way to save the plot points of the average graphs as they are produced. I guess it would something like (sin100average.fig, sin250average.fig, sin500average.fig, etc...).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by