Trouble creating an element-wise nested structure: Subscripted assignment dimension mismatch
조회 수: 1 (최근 30일)
이전 댓글 표시
Below is a sample data set that I am trying to put into a nested structure. Each array is x y z coordinates. I am trying to be able to run some operations in a nested for loop where I can call for each joint do this...then for each frame within each joint do this...
%Joint center locations @ frame 1=[i-1], 2=[i], 3=[i+1] meter
Hi1 = [.9940 .7967 0]; %Hip joint center at i-1
Hi2 = [1.0183 .7959 0]; %Hip joint center at i
Hi3 = [1.0425 .7959 0]; %Hip joint center at i+1
Ki1 = [1.0997 .5053 0]; %Knee joint center at i-1
Ki2 = [1.1223 .5042 0]; %Knee joint center at i
Ki3 = [1.1448 .5039 0]; %Knee joint center at i+1
Ai1 = [1.2413 .1126 0]; %Ankle joint center at i-1
Ai2 = [1.2539 .1081 0]; %Ankle joint center at i
Ai3 = [1.2639 .1037 0]; %Ankle joint center at i+1
Mi1 = [1.3626 .1001 0]; %Metatarsal center at i
Mi2 = [1.3732 .0907 0]; %Metatarsal center at i
Mi3 = [1.3807 .0797 0]; %Metatarsal center at I
My most recent attempt, I tried this to set up the structure:
j(1).f(1) = [1.3626 .1001 0]; %Metatarsal (1) center at i
j(1).f(2) = [1.3732 .0907 0]; %Metatarsal (1) center at i
j(1).f(3) = [1.3807 .0797 0]; %Metatarsal (1) center at I
and got the following error: Subscripted assignment dimension mismatch.
댓글 수: 0
답변 (1개)
KL
2017년 11월 19일
Instead of storing 3 vectors for each joints, I'd recommend using a 3x3 matrix. Place it in a structure with more meaningful names. Something like,
Joints.Hip.Coordinates = [0.9940 0.7967 0;1.0183 .7959 0;1.0425 .7959 0];
Joints.Knee.Coordinates = [other values]
Joints.Metatarsal.Coordinates = ...
if you want to do it for different orientations, just create an array of structs on the top level,
Frame(1).Joints
Frame(2).Joints
if you want to loop through different frames, you can say
for fno = 1:numel(Frame)
Frame(k).Joints.Hips.Coordinates(1,:)
%and so on
end
Do you get the idea?
참고 항목
카테고리
Help Center 및 File Exchange에서 Assembly에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!