Angles from XY coordinates from a matrix
조회 수: 14(최근 30일)
I am generally new to matlab, and any help would be appreciated.
I am currently trying to collect data on joint angles over time. I have figured out how to get joint data from XY coordinates at a single point in time. I would like matlab to be able to calculate joint angle at each time interval.
Here is some example data...
[x1 y1 x2 y2 x3 x4
23 32 45 56 66 54
24 34 46 55 66 55
22 36 44 54 65 56
33 23 43 57 64 53]
Here is the matlab code I have working with...
% Create vectors describing sides of triangle
% Calculate the angle between two of the sides
ang = acosd(dot(P12,P13)/sqrt(sum(P12.^2)*sum(P13.^2)))
Matlab will now pump out the angle for line 1 of the data above.
I would like to be able to have a code that will read the data from a matrix, and then pump out the angles from each line.
Thank you so much for your assistance.
Matt Fig 2012년 11월 13일
편집: Matt Fig 2012년 11월 13일
Seems like a simple FOR loop would do the trick.
for ii = size(a,1):-1:1
P12 = [a(ii,3)-a(ii,1), a(ii,4)-a(ii,2)];
P13 = [a(ii,5)-a(ii,1), a(ii,6)-a(ii,2)];
V(ii) = acosd(dot(P12,P13)/sqrt(sum(P12.^2)*sum(P13.^2)));
Or even a vectorized version:
P12 = [a(:,3)-a(:,1), a(:,4)-a(:,2)];
P13 = [a(:,5)-a(:,1), a(:,6)-a(:,2)];
V = acosd(dot(P12,P13,2)./sqrt(sum(P12.^2,2).*sum(P13.^2,2)))
Jürgen 2012년 11월 13일
two possibilities if you want to process a lot of data
: you can use loops or vectorize,
in this case, with few iterations I would use a for loop
so for Counter= 1: NumberOfRowsInMatrixa ... assign values ... do your calculations ... assign results to ResultsMatrix