Saving .mat file with different names
30 次查看(过去 30 天)
显示 更早的评论
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.
回答(2 个)
Bjorn Gustavsson
2019-2-22
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
0 个评论
rahul PAL
2022-11-30
for k = 1 : 12
a = rand;
b = rand;
filename = sprintf('datset_%06d.mat',k)
save(filename,'a','b')
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Testing Frameworks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!