move file which name is changing iteratively in a for loop

2 ビュー (過去 30 日間)
Au.
Au. 2022 年 1 月 18 日
コメント済み: Au. 2022 年 1 月 20 日
Hello all,
I am generating an array in a loop where i apply a certain number of operations to get my Output_array. I save my Output_array under a file name that has to change at each iteration. I need to move the saved file in a different folder than the folder i saved it in.
So far, i tried movefile and copyfile, but the file name has to be a character vector or string scalar. I ended up with the unesthetic solution of indicating the path before the operation and where i want the file the be saved in:
for n=1:size(file_list,1)
cd(filePath)
(... my operations)
Output_array=final_array;
newfilename= sprintf('output_%i.dat',n);
cd(filePath_save)
dlmwrite(newfilename,Output_array,'delimiter','\t'); % i need to save with this format
end
It works, but i was wondering if there would be a better way to do.
Thank you!
A.S
  5 件のコメント
Stephen23
Stephen23 2022 年 1 月 19 日
If moving the files is required then at least use FULLFILE and absolute/relative filenames.
Avoid CD.
Au.
Au. 2022 年 1 月 20 日
I didn't understand that fullfile could save in a different folder by reading the documentation - i thought it was another way to indicate a relative path.
Thank you Stephen and Simon!

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

回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by