0
votes

I need some help with forming a loop to plot some data.

I have five skeletal joints; each JOINT matrix contains an x,y & z coordinate at a certain point in time. x, y and z are the columns, the coordinates in each row. e.g.

 x   y   z
 0.5 0.6 1.3

The four joints are synchronised, the same row in each JOINTS 1, 2 3 and 4 was captured at the same time. I am trying to join these joints up to see what how the user was moving their arm. For reference these are the joints that were captured in the right arm. Joint 1 = shoulder, 2 = elbow, 3 = wrist, 4 = hand.

I wish to be able to plot these joints continuously by going through each row and plotting the line. The matrix size always changes based on the person I am tracking, so I need to loop through each rows of the matrices for joints 1, 2, 3 and 4 and plot the line, increment a row, then plot the next line.

Minimal Example:

J = JOINT(1,:)
% Joint rows varies between each user. I would like a function to 
% extract rows, plot, move onto next row, plot. (ideally with a second delay)
X1 = J(:,1);
Y1 = J(:,2);
Z1 = J(:,3);

line(X1 Y1 Z1)

Actual Code:

CA = JOINT1(13,:); 
CB = JOINT2(13,:);
CC = JOINT3(13,:);
CD = JOINT4(13,:);

X1 = CA(:,1);
Y1 = CA(:,2);
Z1 = CA(:,3);
X2 = CB(:,1);
Y2 = CB(:,2);
Z2 = CB(:,3);
X3 = CC(:,1);
Y3 = CC(:,2);
Z3 = CC(:,3);
X4 = CD(:,1);
Y4 = CD(:,2);
Z4 = CD(:,3);


line([X1, X2, X3, X4],[Y1, Y2, Y3, Y4], [Z1, Z2, Z3, Z4]);

so I assume it would be something like

 [x y] = size(JOINT1);
 figure;
 for i=1:x
    plot(JOINT1(i,:));
    hold on;
    plot(JOINT2(i,:));
 end

I would like to see these on a one second delay, but I can attempt this myself once I automate this method of plotting!

Additionally, if anyone is aware of how I can plot a circle on the coordinates of each joint (e.g. X1, Y1, Z1) that would also be very handy as eventually I would like to look at the angles between joints.

Any help would be appreciated

1
Please provide a Minimal, Complete, and Verifiable example.excaza
Do you want to connect all joints per time step (i.e. joint1, 2, 3 ,4 at time 1 form a polygon, at time 2 they form a polygon etc), or connect one joint through all time, i.e. a line connecting joint1 at t1 to joint1 at t2 etc, connecting joint2 at t1 to joint2 at t2 etc?Adriaan
I think at the moment I would like to connect all joints per time step. So in the example I posted above I am joining the co-ordinates on the 13th second (I am cycling manually through the rows of each joints) BUT i would like it to plot each line with a second delay in between.Josh Robertson

1 Answers

0
votes
name_matrix = {'JOINT2' 'JOINT3' 'JOINT4'};
coord = {'X' 'Y' 'Z'};
for r = 1:size(JOINT2,1); 
    for index = 1:3
    eval([ 'matrix = ' name_matrix{index} ';' ])
    for c = 1:3
        eval ([ coord{c} num2str(index) ' = matrix(r,c);'])
    end

end
line([X2 X3 X4], [Y2 Y3 Y4], [Z1 Z2 Z3]);
pause(1);
end