Saving multiple files in one folder
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
University
le 21 Oct 2023
Modifié(e) : Walter Roberson
le 22 Oct 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
0 commentaires
Réponse acceptée
Walter Roberson
le 21 Oct 2023
Modifié(e) : Walter Roberson
le 21 Oct 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!