Transform a workspace variable into single .mat files
7 次查看(过去 30 天)
显示 更早的评论
Dear all,
I cut out the first and last minute of my movement data. Additionally used only a specified time window of my data. I saved my data using:
trimmed_raw_data_together = {data.acc_pelvis_time_equal}.';
However, this new workspace variable is a 9x1 cell:
I would like to save each row as one single .mat file as shown above:
Figure 1 is processed data, figure 2 is raw data. Ideally I would like to name processed data similar to the raw data (e.g. pair#1_together_processed) as an iteration.
Kind regards and thank you very much for your support an suggestions.
Jonas
4 个评论
prasanth s
2023-1-27
to Store the specified fields of the specified scalar structure as individual variables in the file. For example, save('filename.mat','-struct','S','a','b') saves the fields S.a and S.b.
Stephen23
2023-2-8
"Ideally I would like to name processed data similar to the raw data (e.g. pair#1_together_processed) as an iteration."
Ideally you would have exactly the same variable names in every MAT file, then your data importing and exporting will be simpler and much more robust than having changing variable names. By all means number the filenames sequentially, but if you want to reduce wasted time (writing code, debugging code, running code), keep the variable names constant.
采纳的回答
Vinayak Choyyan
2023-2-8
Hi Jonas,
As per my understanding, you have a cell array, trimmed_raw_data_together, and you would like to store each element of the cell array to a different .mat file. You would also like to have a custom name to the mat file which depends on the iteration or element number of the cell array.
Please refer to the following code to do the same. Do note, this code will save each element of the cell array in a different .mat file with the variable name as data. If you would like to change the name of the variable being stored inside the .mat file, please change the variable named data in the below code. I have marked the two places you will have to change this name with the comment here.
for i=1:length(trimmed_raw_data_together)
matFilenames="pair#"+i+"_together_processed.mat";
data=trimmed_raw_data_together{i};%here
save(matFilenames,'data');%here
end
I hope this resolves the issue you are facing. Please refer to the following documentation if you would like to read more on how to save variables to files. Save workspace variables to file - MATLAB save - MathWorks India
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!