angle between 2 vectors each time
Afficher commentaires plus anciens
Hello,
I'm working with experimental data, and I want to calculate a angle between 2 lines or vectors for each group of points that changes through time.
My code to do it is:
for j = 1:size (dados,1);
x1 = o_x;
x2 = q_x;
y1 = o_y;
y2 = q_y;
x3 = q_x;
x4 = j_x;
y3 = q_y;
y4 = j_y;
vetor1 =[ x1(j),y1(j)]-[x2(j),y2(j)];
vetor2 = [x3(j),y3(j)]-[x4(j),y4(j)];
angulo(j+1,1) = acos( dot (vetor1(j),vetor2(j))./ norm(vetor1))./norm(vetor2);
end
My data is like it:
time o_x o_y ...
0.01 234 364
0.02 253 456
(...)
0.03 286 654
And the error is
??? Index exceeds matrix dimensions.
Can you help me?
Réponses (1)
Walter Roberson
le 26 Juin 2012
vetor1(j,:) =[ x1(j),y1(j)]-[x2(j),y2(j)]; vetor2(j,:) = [x3(j),y3(j)]-[x4(j),y4(j)];
angulo(j+1,1) = acos( dot (vetor1(j,:),vetor2(j,:))./ norm(vetor1(j,:)))./norm(vetor2(j,:));
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!