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!
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!