Saving multiple files in one folder

4 visualizaciones (últimos 30 días)
University
University el 21 de Oct. de 2023
Editada: Walter Roberson el 22 de Oct. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Oct. de 2023
Editada: Walter Roberson el 21 de Oct. de 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 comentarios
Walter Roberson
Walter Roberson el 21 de Oct. de 2023
Corrected.
University
University el 22 de Oct. de 2023
Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by