MATLAB Answers

saving multiple .mat files with the same name from a script

조회 수: 8(최근 30일)
AUWAL ABUBAKAR
AUWAL ABUBAKAR 3 Dec 2019
Good day,
Please how can I save a variable in a folder each time i run my script.
For instance, I have two outputs; test=[2,5,8] and test=[1,2,3] by runing the script twice.
I use save ('data.mat','test'); to save the variable as data.mat file. But each time i run the script for the second time it replaces the first .mat file.
Is there any way it could be save as data1.mat, data2.mat ......data20.mat (if i run the script 20 times) so that i can call it for later use?
Also, an insight on how to load all the .mat files will be appreciated
Thanks

  댓글 수: 0

로그인 to comment.

답변 수 (2)

Rik
Rik 3 Dec 2019
Use sprintf to form the file names with a number.
During the loading, you should load to an output variable and store all the data in a large array, don't attempt to generate numbered variables.

  댓글 수: 0

로그인 to comment.


Stephen Cobeldick
Stephen Cobeldick 3 Dec 2019
"Is there any way it could be save as data1.mat, data2.mat ......data20.mat (if i run the script 20 times)..."
You could download my FEX submission nextname, which was designed for exactly that situation:
It has plenty of examples in the online description, the Mfile help, and the HTML documentation, so you should not have any difficulties using it.

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

제품


릴리스

R2019a

Translated by