Borrar filtros
Borrar filtros

Transform a workspace variable into single .mat files

2 visualizaciones (últimos 30 días)
Jonas Bender
Jonas Bender el 26 de En. de 2023
Comentada: Stephen23 el 8 de Feb. de 2023
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 comentarios
prasanth s
prasanth s el 27 de En. de 2023
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 el 8 de Feb. de 2023
"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.

Iniciar sesión para comentar.

Respuesta aceptada

Vinayak Choyyan
Vinayak Choyyan el 8 de Feb. de 2023
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

Más respuestas (0)

Categorías

Más información sobre MATLAB Compiler en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by