How to save multiple .mat files as one .mat file?

조회 수: 33 (최근 30일)
David Mascarenhas
David Mascarenhas 2021년 7월 1일
댓글: David Mascarenhas 2021년 7월 31일
Hello,
I have a matlab script that processes some data for each hour of the day and saves each result as > " result_ddmmyy_hh.mat " file.
This gives me a file of all the resultant data processed for that hour.
I use this script on a loop to study the data for the whole day and then the same for the whole week.
Now I have too many files (24 X 7). I would like to store all the results of each day as one complete file, that way i will have only 7 meta-data files.
Is there a way to do this directly without re-running the entire script? Can I directly merge multiple .mat files into one .mat file?
Thank you in advance!
David :)

채택된 답변

Jeff Miller
Jeff Miller 2021년 7월 2일
You can load all 24 .mat files for a single day and then save all of the collected variables together as one .mat file. For example:
Collected = cell(24,1);
for Hour=1:24
fname = ['FileForHour' num2str(Hour) '.mat'];
Collected{Hour} = load(fname);
end
save('CollectedForThisDay','Collected')
Details might change a bit depending on how the hourly variables are named and how you want them named in the collected file.
  댓글 수: 3
Jeff Miller
Jeff Miller 2021년 7월 2일
No, the method will save the variables for all hours---not just the last one.
For example, Collected{1}.Var1 will be the value of Var1 for the first hour, Collected{2}.Var1 wil be the value of Var1 for the second hour...Collected{24}.Var1, and so on for all variables.
In the saved file, you can think of each Collected{k} as a folder with its own collection of variables.
David Mascarenhas
David Mascarenhas 2021년 7월 31일
This works!!
I had to adjust some of my data, but the idea is fantastic.
Thank you! :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by