angle between 2 vectors each time
显示 更早的评论
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?
回答(1 个)
Walter Roberson
2012-6-26
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,:));
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!