Finding cosine of angle formed by two adjacent points of a curve and horizontal line
3 views (last 30 days)
Show older comments
Vahid Esmaeili
on 21 Jul 2020
Commented: Vahid Esmaeili
on 24 Jul 2020
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 Comments
Accepted Answer
Kiran Felix Robert
on 24 Jul 2020
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
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!