How to save a plot as a file, after each iteration off a for loop.

1 Ansicht (letzte 30 Tage)
I was wondering if it's possible to save a plot after each iteration of a for loop, and adda Date, Latitude and Longtitude to the title?
Here is the script I'm working on(the variables are added from a 5 column cell array(newdata)):
D = newdata(:,2);%depth
S = newdata(:,1); %salinity
t1 = cell2mat(newdata(:,3)); %days since 1950-01-01
t2 = 19500101;
t3 = datetime(t2,'ConvertFrom','yyyymmdd');
t4 = juliandate(t3);
t5 = t1 + t4;
T = datetime(t5,'convertfrom','juliandate'); %datenumtime
Lat = newdata(:,4);
Long = newdata(:,5);
[L,W] = size(newdata);
for i = 1 : L
x = S{i,1};
y = D{i,1};
plot(x,y),hold on
scatter(x,y),hold off
legend
xlabel('Salinity')
ylabel('depth [m]')
end
Would appreciate som help.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 14 Apr. 2020
Bearbeitet: Ameer Hamza am 14 Apr. 2020
See exportgraphics(): https://www.mathworks.com/help/matlab/ref/exportgraphics.html. You can call it inside the for loop to save the figures
for i = 1 : L
x = S{i,1};
y = D{i,1};
plot(x,y),hold on
scatter(x,y),hold off
legend
xlabel('Salinity')
ylabel('depth [m]')
title(sprintf('Date:%s Lat:%d Lon:%d', string(t5(i)), Lat(i), Long(i)));
exportgraphics(gca, ['file' num2str(i) '.png'])
end
  15 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by