Saving .mat file with different names

38 ビュー (過去 30 日間)
TANMAYEE PATHRE
TANMAYEE PATHRE 2019 年 2 月 22 日
回答済み: rahul PAL 2022 年 11 月 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
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

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

カテゴリ

Help Center および File ExchangeTesting Frameworks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by