save ensure automatic renaming

조회 수: 9 (최근 30일)
Wouter Verstraelen
Wouter Verstraelen 2019년 6월 7일
편집: Stephen23 2019년 6월 7일
I am running a script repeatedly each time changing a few parameters, each time evaluation takes at least a few hours. At the end of my code, I put
save('myfilename.mat').
Now, each time, I have to ensure I change myfilename to avoid any data gets overwritten. Is there a way to ensure that if 'myfilename.mat' already exists, matlab saves the second .mat file as 'myfilename(1).mat' etc?
  댓글 수: 2
Stephen23
Stephen23 2019년 6월 7일
편집: Stephen23 2019년 6월 7일
This is exactly what my FEX submission is intended for:
It is designed to work efficiently even when there are a large number of files, and does not rely on a particular loop or continual code evaluation.
Wouter Verstraelen
Wouter Verstraelen 2019년 6월 7일
@Stephen thanks!

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 6월 7일
There is no automatic way to do that. You can write your own code for the purpose.
filenum = 0;
while true
filenum = filenum + 1;
filename = sprintf('myfilename_%d.mat', filenum);
if ~exist(filename, 'file'); break; end
end
save(filename);
  댓글 수: 1
Wouter Verstraelen
Wouter Verstraelen 2019년 6월 7일
thanks! I'd believe it would be great if in the future there could just be some kind of flag to the save-command though.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by