Finding cosine of angle formed by two adjacent points of a curve and horizontal line
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I am wondering how to calculate the cosine of the angle formed by two very close points and the horizontal line in MATLAB? I want to find the cosine between every pair of adjacent points in a matrix. Please find a matrix ( of 1761 rows and 1 column in the attached EXCEL file).
Thank you so much,
0 个评论
采纳的回答
Kiran Felix Robert
2020-7-24
Hi Vahid,
It is my understanding that you attempt to find the angle between the line formed by joining two adjacent points and the x-axis. Also use that to find angle between lines formed by every pair of adjacent points. The angle with the x-axis or the horizontal can be calculated as shown below, assuming B is the input Vector,
angle = zeros(length(B)-1,1); % Pre-allocating angles vector
for i = 1:(length(B)-1)
x = [i i+1];
y = [B(i) B(i+1)];
slope = (y(2) - y(1))/(x(2)-x(1));
angle(i) = atand(slope); % Angle in degrees
end
Angle between the lines can be calculated by simply subtracting the values in the angle vector.
angle1 = angle(2) - angle(1);
Thanks
Kiran
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!