Automated process to save outputs into various MAT files

조회 수: 1 (최근 30일)
Karthik Nagaraj
Karthik Nagaraj 2020년 2월 20일
댓글: Karthik Nagaraj 2020년 2월 28일
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.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 2월 22일
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
Karthik Nagaraj
Karthik Nagaraj 2020년 2월 28일
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

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

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by