i have a loop which runs from 1 to 7 producing four different figures per run. How do i automatically save each of these figures inside the loop. The loop is given below.

1 vue (au cours des 30 derniers jours)
for n = 1:7
elevation = A_SATPOS(n).ELEV*(180/pi);
for PRN = 8
figure(); %first figure
subplot(2,1,1)
plot(elevation(first_half,PRN,1),MP1(first_half,PRN),'-','LineWidth',1)
ylabel('Multipath [cm]')
ylim([-35 35]);
xlabel('Elevation [degrees]')
%xlabel((sprintf('Time [hours] %s', days{day})))
title (sprintf('GPS L1 [HEL2] 00:00 - 11:59, G%s, %s', satNo{PRN}, days{n}));
%legend('Multipath','Elevation angle')
set(gca,'XLim',[0 90])
set(gca,'XTick',(0:10:90))
grid minor
subplot(2,1,2)
plot(elevation(second_half,PRN,1),MP1(second_half,PRN),'-','LineWidth',1)
ylabel('Multipath [cm]')
ylim([-35 35]);
xlabel('Elevation [degrees]')
%xlabel((sprintf('Time [hours] %s', days{day})))
title (sprintf('GPS L1 [HEL2] 12:00 - 23:59, G%s, %s', satNo{PRN}, days{n}));
%legend('Multipath','Elevation angle')
set(gca,'XLim',[0 90])
set(gca,'XTick',(0:10:90))
grid minor
for ob_type = 1
cno = A_OBS(n).CN0;
figure() %second figure
yyaxis left
plot(new_time, cno(:,PRN,ob_type),'-','LineWidth',1)
ylabel(sprintf('%s, CNO [dB-Hz]', cn0type{ob_type}))
ylim([0 60]);
set(gca,'YTick',(0:5:60))
yyaxis right
plot(new_time, MP1(:,PRN),'-','LineWidth',1)
ylim([-35 35]);
%set(gca,'XLim',[0 60])
set(gca,'XLim',[0 24])
set(gca,'xTick',(0:4:24))
xlabel('GPS Time [hours]')
ylabel('Multipath [cm]')
title (sprintf('GPS L1 [HEL2], G%s, %s', satNo{PRN}, days{n}));
grid minor
legend('CNO','MP')
end
end
%end
%% L2
%for n = 1:7
elevation = A_SATPOS(n).ELEV*(180/pi);
for PRN = 8
figure() % third figure
subplot(2,1,1)
plot(elevation(first_half,PRN,1),MP2(first_half,PRN),'-','LineWidth',1)
ylabel('Multipath [cm]')
ylim([-35 35]);
xlabel('Elevation [degrees]')
%xlabel((sprintf('Time [hours] %s', days{day})))
title (sprintf('GPS L2 [HEL2] 00:00 - 11:59, G%s, %s', satNo{PRN}, days{n}));
%legend('Multipath','Elevation angle')
set(gca,'XLim',[0 90])
set(gca,'XTick',(0:10:90))
grid minor
subplot(2,1,2)
plot(elevation(second_half,PRN,1),MP2(second_half,PRN),'-','LineWidth',1)
ylabel('Multipath [cm]')
ylim([-35 35]);
xlabel('Elevation [degrees]')
%xlabel((sprintf('Time [hours] %s', days{day})))
title (sprintf('GPS L2 [HEL2] 12:00 - 23:59, G%s, %s', satNo{PRN}, days{n}));
%legend('Multipath','Elevation angle')
set(gca,'XLim',[0 90])
set(gca,'XTick',(0:10:90))
grid minor
for ob_type = 2
cno = A_OBS(n).CN0;
figure() % fourth figure
yyaxis left
plot(new_time, cno(:,PRN,ob_type),'-','LineWidth',1)
ylabel(sprintf('%s, CNO [dB-Hz]', cn0type{ob_type}))
ylim([0 60]);
set(gca,'YTick',(0:5:60))
yyaxis right
plot(new_time, MP2(:,PRN),'-','LineWidth',1)
ylim([-35 35]);
%set(gca,'XLim',[0 60])
set(gca,'XLim',[0 24])
set(gca,'xTick',(0:4:24))
xlabel('GPS Time [hours]')
ylabel('Multipath [cm]')
title (sprintf('GPS L2 [HEL2], G%s, %s', satNo{PRN}, days{n}));
grid minor
legend('CNO','MP')
end
end
end

Réponse acceptée

Bjorn Gustavsson
Bjorn Gustavsson le 9 Jan 2023
Modifié(e) : Bjorn Gustavsson le 9 Jan 2023
One thing I regularly do is something like this:
fig_basename = 'My_current_fig';
for i1 = 1:7
%plot-and-decorate-code
figname = sprintf('%s-%03d.eps',fig_basename,i1);
disp(['Now printing: ',figname])
print('-depsc2','-painters',figname)
end
You can adapt as you see fit. Occasionally I also keep a version-number that ticks up everytime I rund the script, to keep all sort of outputs for each run. For example:
% first in script:
load run_id.mat run_id
run_id = run_id+1;
save('run_id.mat','run_id')
% script-work...
% then at time of saving and printing
savename = sprintf('results-run-%d.mat',run_id)
fig_basename = sprintf('My_current_fig-run-%d',run_id);
That sometimes is handy.
HTH
  2 commentaires
osasunmwen efosa
osasunmwen efosa le 9 Jan 2023
Modifié(e) : osasunmwen efosa le 9 Jan 2023
Thanks for the suggestion. The figures are now being save. i used the first set of codes b ut i am unable to view them because they are not saved in jpeg or png format. Any suggestions ?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by