How to extend a best fit line?

Hi, I divided the datapoints of a fault scarp profile into three datasets for the footwall, scarp slope and hanging wall and plotted the respective best fit lines. What is the easiest way to just extend the length of the best fit line for the scarp so that it crosses the best fit lines of the footwall and the hanging wall?

 Accepted Answer

P1 = rand(2,1) ;
P2 = rand(2,1) ;
% line(P1,P2)
plot([P1(1) P2(1)],[P1(2) P2(2)],'b','linewidth',5)
%%Extend line
m = (P2(2)-P1(2))/(P2(1)-P1(1)) ; % slope of line
N = 100 ;
x = linspace(-2,2,N) ; % specify your x limits
y = P1(2)+m*(x-P1(1)) ; % y = y1+m*(x-x1) ;
hold on
plot(x,y,'.r')

6 Comments

Hey, thanks for your time. Took me a little while to get how to apply that to my data, but got it now! ;)
Thanks is accepting the answer.....:)
Ya, but an additional 'thanks' does't hurt...esp. as I'm pretty sure that I will have to ask tons of other annoying questions here ;)
You are welcome...!
Schirin, can you please click the "Accept this answer" link so KSSV gets credit (reputation points) for his efforts to help you.
x1=302;
x2=380;
y1=1;
y2=101;
here is my point of the line . how I increase the size of this line?

Sign in to comment.

More Answers (0)

Categories

Asked:

on 12 Oct 2017

Commented:

on 22 Nov 2018

Community Treasure Hunt

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

Start Hunting!