ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2D-Linear Fit needed

Hello,

I have to find the best straight line in a x-y measurement array.

The "Linear Fit.vi" uses a linear regression method normal to the x-Axes which leads to bad results if the sollution would be near a vertical straight line.

 

e.g.: with a Pair of measurement points with:

1.: x=0 Y=+1

2.: x=0 Y=-1

I would like to get a straigth vertical line (x=0, k=inf or something which represents this), the Linear Fit.vi's result is NaN

 

Does someone know where to find a vi for this?

 

Thank you for any comments.

 Greetings

 

Mario Hirth

 

 

0 Kudos
Message 1 of 5
(3,824 Views)

Hi Mario,

 

one possible workaround is to fit in both directions, i.e. y vs. x and x vs. y.

If you know your data will usually be close to vertical just do the x vs. y fit.

 

Hope this helps,

Daniel

 

0 Kudos
Message 2 of 5
(3,821 Views)

Hello Daniel,

thank you for your quick answer.

I allready had a workaround where I swap x<>y if the y elongation is bigger than the x elongation.

Leading to better results for straight lines in x OR y direction, but not in between (45deg?).

 

Since I use the residuum of the linear fitting to evaluate the measurement (which should represent a straight line, but I dont know in which direction), I have to be mathematically correct.

 

I also had a solution by iteration with: "find slope" => "turn measurement data into x-axis according to slope" => start again with finding slope => do this about 5 times etc...

 

in principle this works, but since I have to make a iteration with the result of this output (which is a different story), I have a iterationtask  inside an iteration task.

It works, but its neither a beatiful sollution nor a quick (means CPU-intensive).

 

But thank you anyhow

 

Mario

0 Kudos
Message 3 of 5
(3,809 Views)

Mario Hirth wrote:

Since I use the residuum of the linear fitting to evaluate the measurement (which should represent a straight line, but I dont know in which direction), I have to be mathematically correct.

 

I also had a solution by iteration with: "find slope" => "turn measurement data into x-axis according to slope" => start again with finding slope => do this about 5 times etc...

 

in principle this works, but since I have to make a iteration with the result of this output (which is a different story), I have a iterationtask  inside an iteration task.

It works, but its neither a beatiful sollution nor a quick (means CPU-intensive).


Mathematically, this makes no sense to me. Can you explain what it is supposed to achieve?

 

What is the error in x and y for each data point?

0 Kudos
Message 4 of 5
(3,783 Views)

Hi altenbach,

Why should this make no sense?

The Linear Fit.vi trys to find a straight line which minimizes the Summ((Delta y)^2) , I want a line which minimizes Summ(Sqrt((Delta x)^2+(Delta y)^2))

In other words, not the deviation in y-direction but in a direction normal to the fitting line.

 

By turning the measurementpoints into the x-axis according to the slope of my fitting line, "y-direction" and "normal to the fitting line" is the same.

 

Shure I have to remember how much I have turned my measurement points, but this is not a real problem.

 

greeting Mario

0 Kudos
Message 5 of 5
(3,769 Views)