Transform a workspace variable into single .mat files

7 ビュー (過去 30 日間)
Jonas Bender
Jonas Bender 2023 年 1 月 26 日
コメント済み: Stephen23 2023 年 2 月 8 日
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
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
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
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 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by