How do I dynamically generate a file name for save in MATLAB

 채택된 답변

Doug Hull
Doug Hull 2011년 1월 18일
You're probably trying
fname = 'foobag';
save fname variable;
To do this correctly, you need to use the "functional" form of save:
fname = 'foobar';
save(fname, 'variable');
In fact, it is true in general that the following two lines are equivalent:
command str1 str2 str3
command('str1', 'str2', 'str3')
This allows one replace any or all of the parameters with dynamically generated strings. This is also useful in commands like PRINT, LOAD, CLEAR, etc.
[From the MATLAB FAQ of Ancient Times]

추가 답변 (2개)

Anish
Anish 2011년 1월 18일
You can use the function form of the SAVE command:
i = 10;
fname = sprintf('myfile%d.mat', i);
save(fname)
For more help, see:
Neha  Singh
Neha Singh 2017년 4월 20일

0 개 추천

How it is possible to save without loop variable? Suppose I took 'x' variable and I want to append at the end of file while saving i.e filex. This show result into file1, file9 somthing like this.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2011년 1월 18일

댓글:

2021년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by