필터 지우기
필터 지우기

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.

답변 (1개)

KL
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?
  댓글 수: 1
monarch
monarch 2017년 11월 19일
Thank you. For the way I need to run these functions, I think I need my joint to be top level rather than my frame...and then be able to cycle through easily. My idea for the nested for loop was something like this:
For j = joint
%do these operations for frame 2 of this joint
for i = 1:3
%do these operations for all frames for this joint
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by