How to combine two trendline from two figures and find the angle?

1 回表示 (過去 30 日間)
Okinawa Rikenata
Okinawa Rikenata 2018 年 2 月 7 日
コメント済み: Okinawa Rikenata 2018 年 2 月 8 日
Halo, i have asked about the same thing before and also i have searched for the solution on Google but still havent found it yet. I have some 117*1 data. Time, x, and y. I make plot for time-x and time-y. So i get two plots and also two trendlines which i get from polyfit. Now im so confused about how to combine these trendlines until i get the intersection and calculate the angle between them. Let's say time=z, x=x, and y=y. So then the plots are z-x and z-y. My teacher told me to look for a solution if z-x and z-y become x-y. Do i need to do some rotation and tranformation? Please help me. Thankyouu.
aa=polyfit(time,x,1); bb=polyval(aa,time); figure plot(time,x) hold on plot(time,bb) cc=polyfit(time,y,1); dd=polyval(cc,time); figure plot(time,y) hold on plot(time,dd)

採用された回答

Roger Stafford
Roger Stafford 2018 年 2 月 7 日
編集済み: Roger Stafford 2018 年 2 月 7 日
polyfit(x,y,1) will give you [p,q] which represents the line y = p*x+q, so ‘p’ will be the slope of such a fitted line. Therefore, to obtain the angle between two such lines, do this
pol1 = polyfit(x1,y1,1); % Where x1,y1 are data for the first line
pol2 = polyfit(x2,y2,1); % and x2,y2 are data for the second line
p1 = pol1(1); % First slope
p2 = pol2(1); % Second slope
ang = atan((p2-p1)/(1+p2*p1));% Angle counterclockwise from line 1 to line 2
This will give an angle lying between pi/2 and -pi/2. If you want it to lie between 0 and pi, replace the last line above by
ang = mod(atan((p2-p1)/(1+p2*p1)),pi);
[Note: You do not need to find the intersection of the lines to determine this angle.]

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by