Naming Vectors with Nested For Loop Variables

3 次查看(过去 30 天)
I am currently working on a project where I have multiple data sets. I have one excel file that I have loaded into Matlab that is broken down into several components. I have 10 Patients and each patient has 4 Different Conditions. Within Each condition there are 8 1x3 vectors, signifying three coordinates (x,y,and z) My question is...Is there a way to name each vector based on both patient # and condition #?
For example, if I would like to do computations on Left_Ankle_Coordinates for Patient 2 with condition 2, is there a way to name it in a way where I know both the patient # and condition #, like Left_Ankle_Coordinates_2_2? I would like to put all of this in a for loop and then write to excel.
Any help would be greatly appreciated!

回答(1 个)

Iain
Iain 2014-8-6
You're asking for something like this, modified for exactly what you want (i.e., the real data, rather than ones).
list1 = {'left','right','top','bum'};
list2 = {'A','B','C','D','E','F'};
list3 = {'1','12','34',73'};
for i = 1:5
for j = 1:6
for k = 1:4
name = [list1{i} '_' list2{j} '_' list{3}];
eval([name ' = ones(8,1);' ])
end
end
end
Its really nasty from a programming point of view. You would be much better simply indexing a large array, or cell array:
for patient = 1:10
for condition = 1:10
Left_ankle{patient}{condition} = ones(8,1);
end
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by