LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in Decimate 1D Array

Solved!
Go to solution

There appars to be a Bug in Decimate 1D Array function as I understand it should work.

 

See the attached VI.

 

In LabVIEW 2010 VI attached, I have 2 Decimate 1D Array functions. Each has exactly 16 outputs. Then I Initialize 2 arrays, one has 16 elements, the second array only has 1 element.

 

The Decimate function that is feed 16 elements returns the appropriate output values.

 

The Decimate function that is fed the smaller array retuns Zero as the first element, which is incorrect. The first element is not zero.

 

The LabVIEW documentation (LOL) does not mention what will happen when the size of the input array to the Decimate 1D Array function is less than the number of outputs. One would suppose that the Deimate function would return all of the elements that were present in the array and empty arrays on the remainder.

 

Why doesn't the Decimate 1D Array function work as expected in cases where the input array size is less than the number of outputs? Is this a BUG ? Is there a workaround?

0 Kudos
Message 1 of 6
(3,088 Views)

Interesting behavior.  I think it's definitely a documentation bug since I agree it's not intuitive that if N outputs > Array Size In, the result will be an empty array.

 

Workaround would be to do an array size check before calling decimate.

0 Kudos
Message 2 of 6
(3,070 Views)
Solution
Accepted by topic author dbaechtel

Actually the detailed help for Decimate array does tell what happens when the # of elements is too few.  And the result you are seeing is not a bug.

 

Quote from detailed help

 

"If you remove one element from the input array there will only be 15 elements. The last decimated array will only have 3 elements (3, 7, and 11) since element 15 was deleted. Since the function will only return arrays of the same size, the other 3 decimated arrays will drop their last element so that all of the arrays now contain 3 elements."

 

So all output arrays are truncated to the shortest array.  Since array 1 has 1 element and all the rest have zero elements, they are all truncated to zero elements.  When you index an array to an index that does not exist (such as the 0th element of an empty array), you get the default datatype for that array.

Message 3 of 6
(3,069 Views)

From the LV Help:

 

elements 0, n, 2n, ... is the first output array. The function stores array[0] at index 0 of the first output array, array[1] is stored at index 0 of the second output array, array[n-1] at index 0 of the last output array, array[n] at index 1 of the first output array, and so on, where n is the number of output terminals for this function.

For example, assume the array has 16 elements and that you wire four output arrays. The first output array receives elements 0, 4, 8, and 12. The second output array receives elements 1, 5, 9, and 13. The third output array receives elements 2, 6, 10, and 14. The last output array receives elements 3, 7, 11, and 15. This is the expected behavior.

If you remove one element from the input array there will only be 15 elements. The last decimated array will only have 3 elements (3, 7, and 11) since element 15 was deleted. Since the function will only return arrays of the same size, the other 3 decimated arrays will drop their last element so that all of the arrays now contain 3 elements.

 

It is all or nothing, not enough elements in your array, values get dropped.  You may disagree with this behavior, but it is expected and documented.  The workaround is to roll your own.

 

0 Kudos
Message 4 of 6
(3,065 Views)

Ah, I guess Ravens has better reading comprehension than me.

 

I still think the language is a bit confusing.

0 Kudos
Message 5 of 6
(3,062 Views)

I think what you are seeing is the expected result.  The detailed help describes how the output arrays are shortened to to provide equal length arrays for all of the outputs.  So when the number of elements in the array is not an integer multiple of the decimation factor, the output arrays will not contain all the data in the input array.

 

Put indicators on the decimated arrays.  The second one is empty, which is consistent with the help.

 

Lynn

0 Kudos
Message 6 of 6
(3,058 Views)