Saving multiple files in one folder

4 Ansichten (letzte 30 Tage)
University
University am 21 Okt. 2023
Bearbeitet: Walter Roberson am 22 Okt. 2023
Hi, Please how can I save multiple figurea as png into a single folder? I tried this although is "fig" but it only save the last image.
path = 'C:\fig_test' ;
N = 6 ;
for k = 1:N
% theta vs x at point x=0 and y=0
figure(1)
hold on
lgd = ['\xi = ',num2str(xivals(i))];
plot(xarray, squeeze(theta(i, yl, 1:nx, nt)), 'DisplayName',lgd)
xlabel('y[m]')
ylabel('\theta [rad]')
xlim([xmin xmax])
hold off
legend('Location','best')
% velocity in x-direction vs y
figure(2)
hold on
plot(yarray, u(i, 1:ny, xl, nt), 'DisplayName',lgd)
xlabel('y[m]')
ylabel('u [m/s]')
hold off
legend('Location','best')
% velocity in y-direction vs y
figure(3)
hold on
plot(yarray, squeeze(v(i, 1:ny, xl, nt)), 'DisplayName',lgd)
xlabel('y[m]')
ylabel('v [m/s]')
hold off
legend('Location','best')
% theta vs time at x=0 and y=0
figure(4)
hold on
plot(tarray, squeeze(theta(i, yl,xl, 1:nt)), 'DisplayName',lgd)
xlabel('time [sec]')
ylabel('\theta [rad]')
hold off
legend('Location','best')
% theta vs x at x from 251 to 301 and y=0
figure(5)
hold on
plot(xarray(251:301), squeeze(theta(i, yl, 251:301, nt)), 'DisplayName',lgd)
xlabel('x [m]')
ylabel('\theta [rad]')
hold off
legend('Location','best')
% velocity in x-direction vs x at x from 251 to 301 and y=0
figure(6)
hold on
plot(xarray(251:301), squeeze(u(i, yl, 251:301, nt)), 'DisplayName',lgd)
xlabel('x [m]')
ylabel('v [m/s]')
hold off
legend('Location','best')
filename = [path, filesep, 'myfigure',num2str(k)] ;
savefig(filename)
end
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Okt. 2023
Bearbeitet: Walter Roberson am 21 Okt. 2023
figpath = 'C:\Users\8765309\fig_test' ;
% theta vs x at point x=0 and y=0
figure(1)
hold on
lgd = ['\xi = ',num2str(xivals(i))];
plot(xarray, squeeze(theta(i, yl, 1:nx, nt)), 'DisplayName',lgd)
xlabel('y[m]')
ylabel('\theta [rad]')
xlim([xmin xmax])
hold off
legend('Location','best')
% velocity in x-direction vs y
figure(2)
hold on
plot(yarray, u(i, 1:ny, xl, nt), 'DisplayName',lgd)
xlabel('y[m]')
ylabel('u [m/s]')
hold off
legend('Location','best')
% velocity in y-direction vs y
figure(3)
hold on
plot(yarray, squeeze(v(i, 1:ny, xl, nt)), 'DisplayName',lgd)
xlabel('y[m]')
ylabel('v [m/s]')
hold off
legend('Location','best')
% theta vs time at x=0 and y=0
figure(4)
hold on
plot(tarray, squeeze(theta(i, yl,xl, 1:nt)), 'DisplayName',lgd)
xlabel('time [sec]')
ylabel('\theta [rad]')
hold off
legend('Location','best')
% theta vs x at x from 251 to 301 and y=0
figure(5)
hold on
plot(xarray(251:301), squeeze(theta(i, yl, 251:301, nt)), 'DisplayName',lgd)
xlabel('x [m]')
ylabel('\theta [rad]')
hold off
legend('Location','best')
% velocity in x-direction vs x at x from 251 to 301 and y=0
figure(6)
hold on
plot(xarray(251:301), squeeze(u(i, yl, 251:301, nt)), 'DisplayName',lgd)
xlabel('x [m]')
ylabel('v [m/s]')
hold off
legend('Location','best')
N = 6 ;
for k = 1:N
filename = fullfile(figpath, "myfigure" + k + ".fig"] ;
savefig(k, filename)
end
  4 Kommentare
Walter Roberson
Walter Roberson am 21 Okt. 2023
Corrected.
University
University am 22 Okt. 2023
Thank you

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by