02-12-2018 09:28 AM
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
Solved! Go to Solution.
02-12-2018 10:44 AM
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?
02-12-2018 10:57 AM
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?
02-12-2018 11:08 AM
Please find attached code and some data.
02-12-2018 11:12 AM
Here is the data in compressed file.
02-12-2018 11:42 AM
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.?
02-12-2018 12:19 PM
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 ?
02-12-2018 12:54 PM - edited 02-12-2018 01:09 PM
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.
To draw the best fit line, create a ramp over the desired x-range and use "linear evaluation" using the fit result.
02-12-2018 01:15 PM
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.
02-12-2018 01:34 PM
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 ?