Showing results for 
Search instead for 
Did you mean: 

Sum Array Elements resetting before completion of array elements

Go to solution

I am attempting to sum the elements of the following array:

[0 10 14 16 20 22 22 24 25 26 26 26 28 28 28 28 27 26 26 26 25 24 22 21 19 16 13 8 0 0 0]. I have tried to do this 3 different ways and all display the same issue -- almost a glitch.


Tracing the LabVIEW code revealed the sum array elements feature (and a loop by hand -- version attached to provide more probing opportunities) both result in the incorrect sum of 84. It appears that the running total is reset twice during the summation process. Since this occurs both by a manual loop and by sum array elements how can I solve this issue? I cannot write a specific exception for this array case as this is a sub-VI for larger code.


The behavior of the code suggests there may be a bug in some LabVIEW VI's but I find this hard to believe as the earlier sum array elements worked perfectly.


Thank you!


LabVIEW 2021 SP1 64-bit Fresh install

0 Kudos
Message 1 of 4
Accepted by topic author CatDoe

U8 can only have numbers up to 255 and your sum exceeds that, causing wrapping according to the established rules of integer math. All you need is insert a conversion to a sufficient datatype (e.g. to I32) before summing.

0 Kudos
Message 2 of 4

In addition, your code makes very little sense overall.


  • You seem to have a 2D array, not a 1D array.
  • It helps if the control contains typical default data so we can test.
  • rotating a 1D array by zero is a NOOP, not a "2. transpose sums array".
  • You can take the sum of the 2D array directly.
  • Not sure how a sum would give you the number of red/black pixels. That depends on the data.

see if this can give you some ideas.




0 Kudos
Message 3 of 4

Thank you for the solution altenbach. I totally forgot U8 has a 255 limit.

0 Kudos
Message 4 of 4