Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
best fit line through coordinates

Subject: best fit line through coordinates

From: Kurt

Date: 16 Oct, 2010 06:02:04

Message: 1 of 7

Hi guys,

I have an issue I'd like some help with.


coordinates =

                    107.35 107 111.51 146
                       117 154.61 111.29 114


In the above matrix 'coordinates', its actually in the form [ x1 y1 x2 y2] for each of the 2 rows.

Is there any function I can obtain a best fit line using these 4 points?


thanks
Kurtis

Subject: best fit line through coordinates

From: Stuart

Date: 16 Oct, 2010 06:25:07

Message: 2 of 7

Go look up the demo on the function polyfit, u can tell it to make a first order regression of those points which would be the line of best fit


"Kurt " <rerty258@gmail.com> wrote in message <i9bf4s$9dq$1@fred.mathworks.com>...
> Hi guys,
>
> I have an issue I'd like some help with.
>
>
> coordinates =
>
> 107.35 107 111.51 146
> 117 154.61 111.29 114
>
>
> In the above matrix 'coordinates', its actually in the form [ x1 y1 x2 y2] for each of the 2 rows.
>
> Is there any function I can obtain a best fit line using these 4 points?
>
>
> thanks
> Kurtis

Subject: best fit line through coordinates

From: Richard Startz

Date: 16 Oct, 2010 15:12:36

Message: 3 of 7

On Sat, 16 Oct 2010 06:25:07 +0000 (UTC), "Stuart "
<imanotarat@gmail.com> wrote:

>Go look up the demo on the function polyfit, u can tell it to make a first order regression of those points which would be the line of best fit
>
>
>"Kurt " <rerty258@gmail.com> wrote in message <i9bf4s$9dq$1@fred.mathworks.com>...
>> Hi guys,
>>
>> I have an issue I'd like some help with.
>>
>>
>> coordinates =
>>
>> 107.35 107 111.51 146
>> 117 154.61 111.29 114
>>
>>
>> In the above matrix 'coordinates', its actually in the form [ x1 y1 x2 y2] for each of the 2 rows.
>>
>> Is there any function I can obtain a best fit line using these 4 points?
>>
>>
>> thanks
>> Kurtis

or

help backslash

Subject: best fit line through coordinates

From: Roger Stafford

Date: 16 Oct, 2010 18:03:03

Message: 4 of 7

"Kurt " <rerty258@gmail.com> wrote in message <i9bf4s$9dq$1@fred.mathworks.com>...
> .........
> In the above matrix 'coordinates', its actually in the form [ x1 y1 x2 y2] for each of the 2 rows.
> Is there any function I can obtain a best fit line using these 4 points?
> .......
- - - - - - - - -
  For best orthogonal fit, rearrange coordinates in the form [x1,y1;x2,y2;x3,y3,x4,y4] and use 'svd'.

Roger Stafford

Subject: best fit line through coordinates

From: Matt J

Date: 16 Oct, 2010 18:29:05

Message: 5 of 7

"Kurt " <rerty258@gmail.com> wrote in message <i9bf4s$9dq$1@fred.mathworks.com>...
>
> In the above matrix 'coordinates', its actually in the form [ x1 y1 x2 y2] for each of the 2 rows.
>
> Is there any function I can obtain a best fit line using these 4 points?
=====

help polyfit

Subject: best fit line through coordinates

From: Kurt

Date: 16 Oct, 2010 19:14:05

Message: 6 of 7

Roger,

do you mean like this? :


X=

107.35 107
111.51 146
117 154.61
111.29 114


[U,S,V] = svd(X)


My question is which component should I use to do the orthogonal fitting?

thanks
kurt

Subject: best fit line through coordinates

From: Roger Stafford

Date: 16 Oct, 2010 23:22:04

Message: 7 of 7

"Kurt " <rerty258@gmail.com> wrote in message <i9cths$hee$1@fred.mathworks.com>...
> Roger,
>
> do you mean like this? :
>
>
> X=
>
> 107.35 107
> 111.51 146
> 117 154.61
> 111.29 114
>
>
> [U,S,V] = svd(X)
>
>
> My question is which component should I use to do the orthogonal fitting?
>
> thanks
> kurt
- - - - - - - - - -
  First you must subtract the coordinates' mean values from them. With your 4 by 2 array X, do this:

X0 = mean(X,1);
[~,~,V] = svd(bsxfun(@minus,X,X0),0); % Economy version
N = V(:,1); % Unit vector in direction of maximum variation

Then the best orthogonal fitting line is

 P = X0 + N*t

as the parameter t varies. This is the direction of maximum variation which means that variation in the orthogonal direction is minimum. The sum of the squares of the points' orthogonal distances to this line is minimized.

  This is distinct from linear regression which minimizes the y variation from the line of regression. That regression assumes that all errors are in the y coordinates, whereas orthogonal fitting assumes the errors in both the x and y coordinates are of equal expected magnitudes.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us