フィルターのクリア

How to save figures from foor loop in separate folders

1 回表示 (過去 30 日間)
Niya Bedzheva
Niya Bedzheva 2019 年 9 月 16 日
コメント済み: Bjorn Gustavsson 2019 年 9 月 16 日
Hello everyone,
i was wondering how can i save the graphics from every foor loop in a different folder named after the file that is running?
here is my code, where i just save them in the directory. But i want matlab to make separate folders where the figures from every run are saved (there are 4 figures per file, and around 5 files per loop)
saveas (h1, sprintf('Experimental_drying_rates_%d.png', i));
saveas (h2, sprintf('Calculated_drying_rates_%d.png',i));
saveas (h3, sprintf('Compariso_experimental_and_calculated_rates_%d.png',i));
saveas (h4, sprintf('Various_drying-air_flowrates_%d.png', i));
thank you in advance!

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 9 月 16 日
Generate your file-names with fullfile (that way you can have multiple directories in a cell-array, one for each of your wanted target dirs):
dirs = {'a','b','c'};
runs = {'Q','W','E','R','T'};
for i1 = 1:numel(runs),
filename1 = [fullfile(dirs{1},runs{i1}),'.png'];
filename2 = [fullfile(dirs{2},runs{i1}),'.png'];
filename3 = [fullfile(dirs{3},runs{i1}),'.png'];
disp(filename1)
disp(filename2)
disp(filename3)
end
HTH
  2 件のコメント
Niya Bedzheva
Niya Bedzheva 2019 年 9 月 16 日
okaay, thank you very much, it can be one solution, buut what if the number of the files for every loop is changing. how can i make the runs to count automatic
Bjorn Gustavsson
Bjorn Gustavsson 2019 年 9 月 16 日
Then I'd save all figures from one run in a run-specific directory, perhaps something like:
runs = {'Q','W','E','R','T'};
files_all_runs = {{'a','b'},{'a'},{'a','b','c','d'},{'a','d'},{'b'}};
for i1 = 1:numel(runs),
for i2 = 1:numel(files_all_runs{i1})
filename1 = [fullfile(runs{1},[runs{i1},'-',files_all_runs{i1}{i2}]),'.png'];
disp(filename1)
end
end
If you somehow autogenerate the files you want from each run you have to do a bit more careful handling of the filenames, but the pattern should be reasonable similar.
HTH

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by