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 and data selection

Subject: Best fit line and data selection

From: John M

Date: 20 Oct, 2010 09:00:06

Message: 1 of 4

Hello,

I have two vectors X and Y, indicating coordinates in a 2D area. The coordinates are data produced from a lab experiment and due to some test 'flows' the data at the first and final rows of the vectors are rubbish.

For this reason I'd like to get the best fit line of the X,Y data considering only the correct values of X,Y.

Although, I know how to plot the best fit line I have no clue how to make a script which will plot the best fit lines without selecting the abnormal values at the beginning and end of the X,Y vectors.

Y =

  1.0e+003 *

         [0
    0.5507
    0.7049
    0.8575
    0.9369
    0.9714
    1.0741
    1.1516
    1.1522
    1.2884
    1.3553
    1.4259
    1.4928
    1.5671
    1.6217
    1.8308
    1.8759
    2.0196
    2.1183
    2.1904
    2.3120
    2.4620
    2.5070
    2.6033
    2.7051
    2.8088
    2.8965
    3.0408
    3.0816
    3.0658
    3.0978
    3.1260
    3.1788
    3.2146
    3.2340];
 

P2=[0.11
1.878
3.208
4.1822
4.5927
4.8798
5.453
6.003
6.1
6.872
7.345
7.803
8.2533
8.7478
9.1838
10.624
10.926
11.905
12.593
13.018
13.975
14.761
15.292
15.803
16.521
17.2447
17.869
18.4158
19.2046
19.0946
19.3159
19.4739
19.8323
20.023
20.203];

Subject: Best fit line and data selection

From: Ross W

Date: 20 Oct, 2010 09:59:06

Message: 2 of 4

"John M" <ioannis.mitsos@gmail.com> wrote in message <i9mb2m$3k3$1@fred.mathworks.com>...
> Hello,
>
> I have two vectors X and Y, indicating coordinates in a 2D area. The coordinates are data produced from a lab experiment and due to some test 'flows' the data at the first and final rows of the vectors are rubbish.
>
> For this reason I'd like to get the best fit line of the X,Y data considering only the correct values of X,Y.
>
> Although, I know how to plot the best fit line I have no clue how to make a script which will plot the best fit lines without selecting the abnormal values at the beginning and end of the X,Y vectors.
>
<snip>

This code discards the first and last rows.

X([1 end])=[];
Y([1 end])=[];

Is that a reliable way to get rid of the bad data? Or do you need to test the values?

Ross

Subject: Best fit line and data selection

From: Wayne King

Date: 20 Oct, 2010 10:16:05

Message: 3 of 4

"John M" <ioannis.mitsos@gmail.com> wrote in message <i9mb2m$3k3$1@fred.mathworks.com>...
> Hello,
>
> I have two vectors X and Y, indicating coordinates in a 2D area. The coordinates are data produced from a lab experiment and due to some test 'flows' the data at the first and final rows of the vectors are rubbish.
>
> For this reason I'd like to get the best fit line of the X,Y data considering only the correct values of X,Y.
>
> Although, I know how to plot the best fit line I have no clue how to make a script which will plot the best fit lines without selecting the abnormal values at the beginning and end of the X,Y vectors.
>
> Y =
>
> 1.0e+003 *
>
> [0
> 0.5507
> 0.7049
> 0.8575
> 0.9369
> 0.9714
> 1.0741
> 1.1516
> 1.1522
> 1.2884
> 1.3553
> 1.4259
> 1.4928
> 1.5671
> 1.6217
> 1.8308
> 1.8759
> 2.0196
> 2.1183
> 2.1904
> 2.3120
> 2.4620
> 2.5070
> 2.6033
> 2.7051
> 2.8088
> 2.8965
> 3.0408
> 3.0816
> 3.0658
> 3.0978
> 3.1260
> 3.1788
> 3.2146
> 3.2340];
>
>
> P2=[0.11
> 1.878
> 3.208
> 4.1822
> 4.5927
> 4.8798
> 5.453
> 6.003
> 6.1
> 6.872
> 7.345
> 7.803
> 8.2533
> 8.7478
> 9.1838
> 10.624
> 10.926
> 11.905
> 12.593
> 13.018
> 13.975
> 14.761
> 15.292
> 15.803
> 16.521
> 17.2447
> 17.869
> 18.4158
> 19.2046
> 19.0946
> 19.3159
> 19.4739
> 19.8323
> 20.023
> 20.203];

Hi John, If your answer to Ross's appropriate question is that you'd like a more general way to exclude outliers from the regression line, the Statistics Toolbox has a nice routine for this called robustfit().

Wayne

Subject: Best fit line and data selection

From: John M

Date: 20 Oct, 2010 13:19:04

Message: 4 of 4

"Wayne King" <wmkingty@gmail.com> wrote in message <i9mfh5$ent$1@fred.mathworks.com>...
> "John M" <ioannis.mitsos@gmail.com> wrote in message <i9mb2m$3k3$1@fred.mathworks.com>...
> > Hello,
> >
> > I have two vectors X and Y, indicating coordinates in a 2D area. The coordinates are data produced from a lab experiment and due to some test 'flows' the data at the first and final rows of the vectors are rubbish.
> >
> > For this reason I'd like to get the best fit line of the X,Y data considering only the correct values of X,Y.
> >
> > Although, I know how to plot the best fit line I have no clue how to make a script which will plot the best fit lines without selecting the abnormal values at the beginning and end of the X,Y vectors.
> >
> > Y =
> >
> > 1.0e+003 *
> >
> > [0
> > 0.5507
> > 0.7049
> > 0.8575
> > 0.9369
> > 0.9714
> > 1.0741
> > 1.1516
> > 1.1522
> > 1.2884
> > 1.3553
> > 1.4259
> > 1.4928
> > 1.5671
> > 1.6217
> > 1.8308
> > 1.8759
> > 2.0196
> > 2.1183
> > 2.1904
> > 2.3120
> > 2.4620
> > 2.5070
> > 2.6033
> > 2.7051
> > 2.8088
> > 2.8965
> > 3.0408
> > 3.0816
> > 3.0658
> > 3.0978
> > 3.1260
> > 3.1788
> > 3.2146
> > 3.2340];
> >
> >
> > P2=[0.11
> > 1.878
> > 3.208
> > 4.1822
> > 4.5927
> > 4.8798
> > 5.453
> > 6.003
> > 6.1
> > 6.872
> > 7.345
> > 7.803
> > 8.2533
> > 8.7478
> > 9.1838
> > 10.624
> > 10.926
> > 11.905
> > 12.593
> > 13.018
> > 13.975
> > 14.761
> > 15.292
> > 15.803
> > 16.521
> > 17.2447
> > 17.869
> > 18.4158
> > 19.2046
> > 19.0946
> > 19.3159
> > 19.4739
> > 19.8323
> > 20.023
> > 20.203];
>
> Hi John, If your answer to Ross's appropriate question is that you'd like a more general way to exclude outliers from the regression line, the Statistics Toolbox has a nice routine for this called robustfit().
>
> Wayne


Hi Wayne,
Thanks a lot, this function does exactly what I want to do!
Very helpful comment. Thanks
John

Tags for 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