Saving multiple files in one folder

4 ビュー (過去 30 日間)
University
University 2023 年 10 月 21 日
編集済み: Walter Roberson 2023 年 10 月 22 日
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

採用された回答

Walter Roberson
Walter Roberson 2023 年 10 月 21 日
編集済み: Walter Roberson 2023 年 10 月 21 日
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 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 21 日
Corrected.
University
University 2023 年 10 月 22 日
Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by