LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Line of best fit issues

Solved!
Go to solution

I have designed a platform where i am extracting data from six different files and plotting them. Using the Linear fit function i should be able to get a line of best fit. But it is not case. Please find attached a figure of the plots with the line of best fit. The y-intercept shows a negative value and the graph crosses at the origin. Also it is not taking into account the plots in the upper part of the graph so that i can get a good line of best fit. Please help me out if possible. Thank you 

0 Kudos
Message 1 of 13
(3,677 Views)

The front panel just display the data, but your error is in the code. The block diagram would be more interesting to troubleshoot the problem. Can you attach your VI and some typical data?

0 Kudos
Message 2 of 13
(3,661 Views)

You'll need to post your code.  Which VIs are you using for fitting, and how its wired, will be pretty important if anyone is to help you out.

 

Are you using the "Curve Fit" Express VIS, the "Linear Fit.vi" or the "Linear Fit Intvl.vi" from the mathematics pallettes or other VIs from somewhere else? 

0 Kudos
Message 3 of 13
(3,658 Views)

Please find attached code and some data.

0 Kudos
Message 4 of 13
(3,650 Views)

Here is the data in compressed file.

0 Kudos
Message 5 of 13
(3,645 Views)

You might try graphing the inputs of the linear fit as well as the best fit curve. It looks like there are 6 values in each array input to the Linear Fit, but only two distinct pairs, one of which is (0,0).

 

You have listed 6 text files, but two of them are duplicates.

I assume you mean that:

'Select file to open 1' should use PV1.txt

'Select file to open 2' should use PV1a.txt

'Select file to open 3' should use PV1.txt, etc.?

0 Kudos
Message 6 of 13
(3,638 Views)

Yes you are right that's how the data should be extracted. You think that i have a data which is (0,0) ? And this is causing the line of best fit to paws through the origin ?

0 Kudos
Message 7 of 13
(3,621 Views)
Solution
Accepted by topic author kishan1994

You have way too much duplicate code and I don't want to sort through it all. Could you right-click the two 2D arrays going into the build array and then via a detour to the linear fit and "create indicator". Same for the other array of clusters going to the xy graph.

 

Now run the VI with all your data. Right-click the indicator terminals and "change to constant" and remove the broken wire going to them. Save the VI under a new name and attach it again. Now we have all the data we need and can focus on the linear fit.

 

And now, going from a 2D array to dynamic data and then to a 1D array probably does not do what you want. Most likely, the linear fit only operates on one dataset instead of all. To include all data, just set the two "build array" nodes (x and y) to concatenate.

 

ConCatEm.png

 

To draw the best fit line, create a ramp over the desired x-range and use "linear evaluation" using the fit result.

0 Kudos
Message 8 of 13
(3,614 Views)

As Christian mentions, there is a lot of duplicate code, and the problem may very well be in the conversion from 2D-Arry to 1D-array using the the dynamic data type. If you create an array indicator for each of the inputs (X and Y) to the Linear Fit VI you should see the input data that I am talking about.

0 Kudos
Message 9 of 13
(3,610 Views)

Yes you are right i just had to set the two build arrays to concatenate and it works. Thanks a lot.

Do you know how i can i extrapolate the line of best fit till the y-intercept ?

0 Kudos
Message 10 of 13
(3,605 Views)