Having trouble with saving multiple figures as they are produced in sequence.
Ältere Kommentare anzeigen
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 Kommentare
Dyuman Joshi
am 26 Jan. 2024
Bearbeitet: Dyuman Joshi
am 26 Jan. 2024
FREQ is not defined. Whereas j is defined but not used.
Is FREQ == j+1?
If you need to get the data points, why not store them while plotting as well?
Also, the use of clear is not needed here, remove those lines.
Owen
am 26 Jan. 2024
Owen
am 29 Jan. 2024
Walter Roberson
am 29 Jan. 2024
%near the top of your code
PLOTNUM = 0;
Then in the place where you save
PLOTNUM = PLOTNUM + 1;
filename = "dddd" + PLOTNUM + ".fig";
save(fig, filename);
Walter Roberson
am 30 Jan. 2024
Which line is showing the error?
PLOTNUM = PLOTNUM + 1;
filename = "dddd" + PLOTNUM + ".fig";
fig = gcf;
save(fig, filename);
Owen
am 30 Jan. 2024
Antworten (1)
the cyclist
am 26 Jan. 2024
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 Kommentar
Kategorien
Mehr zu Printing and Saving finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!