LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in Interpolate 1D for repeated X values?

Using this vi:   LabVIEW 2014:vi.lib:gmath:interp.llb:Interpolate 1D
 
If you have the (X,Y) points (100,1)(100,2)(200,3)(200,4) and you want to interpolate to find a value for X=150, you would expect (hope?!) to get the answer 2.5. However, the VI returns an answer of 2, since it only uses one (probably the second?) of the repeated values…

 

The attached VI illustrates the behaviour, and also a workaround, making the X values ever-so-slightly different, to force the Interpolate 1D to give the correct(?!) answer

0 Kudos
Message 1 of 9
(3,404 Views)

Oh- and I do have a bug report in for this:   (Reference#7446701)

0 Kudos
Message 2 of 9
(3,401 Views)

Why not use the tools from the array palette?

 

(Of course the FOR loop is not needed for a single interpolation value, just tring to duplicate your setup)

 

 

 

0 Kudos
Message 3 of 9
(3,392 Views)

Well... umm... errr... Yep.. That works... 😉

 

I didn't know (or had forgotten) Interpolate 1D Array (one of my favourite VIs) did that..! Do now, reading the help..!

But... it's perhaps not very well behaved if you reverse the Xs...

 

And... I don't think that solution works for my full use case, where I was expecting (obviously incorrectly) Interpolate 1D to perform a linear fit through all the data I gave it- not silently ignore repeated points- before interpolating an output.

 

I guess, describing it like that, I ought just use a linear fit 😉 Interpolate 1D only "joins the dots"- it's perhaps just a little unclear which dots it's going to use...

0 Kudos
Message 4 of 9
(3,373 Views)
The 1D interpolation expects an array with increasing values. Also if the first value in the array is greater than the threshold, it gets lost.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 9
(3,368 Views)

Exactly, so while Altenbach's reply was indeed correct for the example data, it is not robust 😉

0 Kudos
Message 6 of 9
(3,365 Views)
It's not a matter of robustness. It's a matter of you have to be smart about what you do. It's a poor workman who blames his tools.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 7 of 9
(3,349 Views)

@mikeporter wrote:
The 1D interpolation expects an array with increasing values. Also if the first value in the array is greater than the threshold, it gets lost.

Just to clarify here, the Interploate 1D Array function just needs an increasing X value.  The Y values do not need to be sorted at all.  And it performs a linear interpolation between two points surounding the fractional index.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 9
(3,323 Views)

Workarounds- and the wrapping required to make them robust- notwithstanding, do we think it's a bug that Interpolate 1D appears to use only the first of any repeated X values? If it is intended to be simple "join the dots" interpolation, should it not at least use data in the order it appears at its inputs...?

 

Meanwhile, I will replace my use of it with a proper linear fit between my two clumps of data, as I should have done all along... 😉

0 Kudos
Message 9 of 9
(3,289 Views)