Hey. I need a function that does something like this: I give it a collection of (X, Y) points on my graph, plus another X point. Then the output is the Y coordinates in the given X. Something like this:
The blue points are given, and then I give another X value and get it’s Y value. I went through a lot of the mathmatics functions and found nothing that performs this action, so it would be really helpful if anyone could help me find the right VI to do this.
There are at least two classes of methods to do this.
Method1: Lookup Table.
You put the known X,Y points in a table (array) in your code, and you sort the points so that the X values are in order. Then you take your unknown X and search the table, comparing it to the X values in the table, until you find the two points in the table which it is between. Then you perform a calculation called “interpolation” to find the unknown Y value. This might sound difficult but it’s really quite straightforward.
Method2: Mathematical Model
The most common mathematical model is a polynomial. You take all the given data and you try to find a polynomial which fits the data. Once you’ve got the polynomial, you just plug in your unknown X and compute the associated Y value. You can find this polynomial very easily using Excel spreadsheet using the “trendline” feature. Just type your X,Y data into Excel in to two columns, then graph it, then use the trendline feature to find a polynomial of chosen degree.
I’m not a LabVIEW guru and I don’t have LabVIEW installed here, but I believe LabVIEW supports lookup tables. It wouldn’t surprise me if it also has the ability to calculate the coefficients of a polynomial model for you as well. Try searching the LabVIEW help for those words.
Funny, those are actually exactly the two ideas which my friend and I thought of. To be honest, I was convinced LabVIEW is designed to solve these kind of problems with quick and easy-to-use VIs. We will probably go with the second solution. However, are you sure there isn’t a VI that already does this? (not out of lazyness, it’s just very surprising)
You’re looking for the Interpolate 1D function. It’s in the Mathematics>Interpolation & Extrapolation function palette. You can select from many different methods by which it can do its job; the detailed help for the function does a good job of explaining what each method does.