Saving .mat file with different names

38 visualizaciones (últimos 30 días)
TANMAYEE PATHRE
TANMAYEE PATHRE el 22 de Feb. de 2019
Respondida: rahul PAL el 30 de Nov. de 2022
I am doing a test study in which I test the participants for three conditions. Each participant is given an ID (1,2,...etc.). The response of the participants is saved in form or .mat file. I would like to save the response such that NH_ID_Condition. For example, If I am testing for 1st participant and 2nd condition it should save as NH_1_2. How do I use any of the loops so that I dont have to rename the variable after the experiment is finished.

Respuestas (2)

Bjorn Gustavsson
Bjorn Gustavsson el 22 de Feb. de 2019
You can use the functional form of save:
X = data_of_interest1;
Y = data_of_interest2; % and
save_name = sprintf('NH_%03d_%03d.mat',ID,Condition)
save(save_name,'X','Y')
That way you'll create one file with the X and Y data each ID-Condition combination. I strongly suggest that you use
%03d instead of %d when generating your save_name variable. The former will generate names with prepaded zeros like:
NH_001_012.mat - that way it becomes that much easier to list and handle the files in order. Depending on the number of participants and conditions you can change from %03 to whatever suits your needs.
HTH

rahul PAL
rahul PAL el 30 de Nov. de 2022
for k = 1 : 12
a = rand;
b = rand;
filename = sprintf('datset_%06d.mat',k)
save(filename,'a','b')
end

Categorías

Más información sobre Testing Frameworks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by