Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
using structures and for loops
조회 수: 1 (최근 30일)
이전 댓글 표시
I know I'm supposed to use vectorization instead of for loops, but I have to finish this assignement this way so I hope someone is willing to help me anyway.
This is my code:
names2 = {'soleus' 'tibant' 'gaslat' 'vaslat' 'rectfem' 'hamlat'};
Vars2 = {soleus, tibant, gaslat, vaslat, rectfem, hamlat};
nvars = length(Vars2);
for s = 1:1:nvars
for idx=1:10
P(idx).(names2{s}) = zeros(100,3);
end
end
for k = 1:3
for s = 1:1:nvars
for idx=1:10
P(idx).(names2{s})(:,k)= Vars2{s}.(motion{k})(:,1);
end
end
end
When I open P, it contains the same values for P(1).soleus, P(2).soleus, P(3).soleus, ...P(10).soleus,
while all of them should be different since they are data from different subjects.
'soleus' 'tibant' 'gaslat' 'vaslat' 'rectfem' 'hamlat' are structures containing 3 matrices: Gait(100x10), StairUp(100x10) and StairDown(100x10)
The number of colums (10) equals the number of subjects.
댓글 수: 0
답변 (1개)
Guillaume
2015년 12월 22일
"P contains the same values for P(1).soleus, P(2).soleus, P(3).soleus, ...P(10).soleus". Well, yes it would:
P(idx).(names2{s})(:,k)= Vars2{s}.(motion{k})(:,1);
The left hand side depends on idx, the right hand side does not, so of course, the same value is assigned for all idx. Something on the right must also depends on idx.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!