Saving multiple files in one folder

6 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 21 Ott 2023
Modificato: Walter Roberson il 21 Ott 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by