05-24-2021 06:23 AM
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/
05-24-2021 08:12 AM
I don't know MATLAB, but from the looks of it, Interpolate 1D should do it.
05-24-2021 11:40 AM - edited 05-24-2021 11:42 AM
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.
05-24-2021 02:32 PM
05-24-2021 02:50 PM - edited 05-24-2021 02:58 PM
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:
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.
05-24-2021 02:59 PM - edited 05-24-2021 03:01 PM
05-24-2021 03:44 PM
Linear Fit.vi ?
05-24-2021 04:00 PM
05-24-2021 04:43 PM - edited 05-24-2021 04:54 PM
But your x any y values are linearly 100% correlated, meaning for each value of X the value of Y can be calculated.
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!
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?
05-25-2021 03:26 PM - edited 05-25-2021 03:27 PM