Angles from XY coordinates from a matrix
Mostra commenti meno recenti
Hello,
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...
x1=a(1,1);
y1=a(1,2);
x2=a(1,3);
y2=a(1,4);
x3=a(1,5);
y3=a(1,6);
x1=23;
y1=32;
x2=45;
y2=56;
x3=66;
y3=54;
% Create vectors describing sides of triangle
P1=[x1 y1];
P2=[x2 y2];
P3=[x3 y3];
P12=P2-P1;
P13=P3-P1;
% 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.
Example:
ang=
20.049
20.056
..........
..........
etc.
Thank you so much for your assistance.
Risposta accettata
Più risposte (1)
Jürgen
il 13 Nov 2012
0 voti
Hi,
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
end
regardsJ
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!