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.
2 ビュー (過去 30 日間)
古いコメントを表示
osasunmwen efosa
2023 年 1 月 9 日
コメント済み: osasunmwen efosa
2023 年 1 月 9 日
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
0 件のコメント
採用された回答
Bjorn Gustavsson
2023 年 1 月 9 日
編集済み: Bjorn Gustavsson
2023 年 1 月 9 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!