MATLAB Answers

Automated process to save outputs into various MAT files

2 views (last 30 days)
Karthik Nagaraj
Karthik Nagaraj on 20 Feb 2020
Commented: Karthik Nagaraj on 28 Feb 2020
I have numerous covariance matrixes as output from deep neural network and that needs to be stored into various MAT files appending the date and time to the filename. I want to automate the process to save these outputs into various MAT files in a folder.

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 22 Feb 2020
char(datetime('now', 'format', FORMAT_YOU_WANT))
strcat that with the base file name, fullfile() the directory into place, use that as the first parameter to save() with the remaining parameters being the names of the variables to save, expressed as character vectors.

  1 Comment

Karthik Nagaraj
Karthik Nagaraj on 28 Feb 2020
Thank you for response and sorry for my delayed response. I could almost get the idea what you explained, but still have some problems to get the necessary output.
Instead of Cov mat output, I have used a loop for creating magic matrices and store that in a cell here.Then I need to save the indivdual magic matrices as a separate mat file in a specific folder and with filenames in ddmmyss.mat format
n=4;
M=cell(n,1)
f = fullfile('c:\','myfiles','matlab',filesep)
t = datetime('now','Format','dMMyHHmmss')
ct=char(t)
st=strcat(f,ct)
for j = 1:n
M{j} =magic(j) ;
data = M{j};
fnm = sprintf('file_%d.mat',j);
fnm1= sprintf('file_%s.mat',st);
save(fnm,'data');
save(fnm1,'data');
end
In the above code I can save fnm but not the fnm1. I am getting an error
Error using save
Unable to open file "file_c:\myfiles\matlab\28022020115627.mat" for output.
Can you help me the requirment. Thanks

Sign in to comment.

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!