LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Equivalent to MATLAB linear fit

Hello All,

I have the following piece of MATLAB code that I'm looking to bring into LabVIEW, but am not sure how best to do it. The Matlab code is the following:


%define inputs
X = [1D array of X input];
Y = [1D array of Y input];
Z = [1D array of Z outputs;

 

%build fit
fit = fit([X, Y], Z, 'linearinterp');

for u=1:200
Intrerp(u) = fit(Xin(u),Yin(u));
end

I feel like I should be using the LabVIEW interpolate 2d, but for the life of me, can't figure out how to get the inputs to line up.

https://zone.ni.com/reference/en-XX/help/371361R-01/gmath/interpolate_2d/

0 Kudos
Message 1 of 11
(2,682 Views)

I don't know MATLAB, but from the looks of it, Interpolate 1D should do it.

Certified LabVIEW Architect
0 Kudos
Message 2 of 11
(2,643 Views)

I am not familiar with the function "Intrerp". Is that you own or maybe misspelled?

 

Do the x and y value form a regular grid or are distributed randomly in the plane? If they form a rectangular grid, just do a bilinear interpolation.  If they are random, maybe you want to look at interpolate_2d_scattered . I would also strongly recommend to leave out the word "fit". Fitting your data to a model is something else.

 

I guarantee you that you'll get much better answers if you would attach your VI containing some typical example data.

 

0 Kudos
Message 3 of 11
(2,614 Views)

Intrerp is just the result matrix for my display. I'm trying to mimic the fit function, as this is what we currently use in MATLAB.

For reference, here is some code replicating what I'm trying to do.

 

 

0 Kudos
Message 4 of 11
(2,595 Views)

Your VI does not contain any data and has completely unnecessary local variables and sequence structures. Also please don't use the word "complex" unless you are dealing with complex datatype (e.g. CDB). Functionally, you are using Z as indicator, so why is it a control??

 

Code could be simplified as follows, right:

 

altenbach_0-1621886308973.png

 

 

Can you enter typical data into all controls, select all controls and go to menu...edit...make selected values default. Save the VI under a new name and attach it once more.

0 Kudos
Message 5 of 11
(2,588 Views)

Fair,

 

The structure was intentional to better demonstrate the relationship between X, Y and Z inputs.

Here is the vi as it would look in practice

0 Kudos
Message 6 of 11
(2,581 Views)

Linear Fit.vi ?

terickson_0-1621889043115.png

 

CLA
0 Kudos
Message 7 of 11
(2,571 Views)

Linear Fit won't work. The Equation is dependent on both the X and Y variable to produce Z

0 Kudos
Message 8 of 11
(2,565 Views)

But your x any y values are linearly 100% correlated, meaning for each value of X the value of Y can be calculated.

 

altenbach_0-1621892457337.png

 

You can interpolate in 1D using either x or y. Same result! Right?

I assume you only want to interpolate, and not extrapolate.

 

You currently don't have sufficient information to generate values for your xi, yi because they don't lie on that line where x and y are defined!

 

altenbach_0-1621893177878.png

 

 

If this correlation is not the case in general, please provide more realistic data.

What result do you get from the sample data using your Matlab code?

 

0 Kudos
Message 9 of 11
(2,550 Views)

All,

 

Here's another VI that demonstrates the issue in a different way.

 

This VI contains a full (X,Y) data correction field (taken with 5 unit spacing) 

I need to use this filed to interpolate any given (Xi , Yi). 

 

EDIT wrong VI

0 Kudos
Message 10 of 11
(2,496 Views)