LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to increment an element in an array and put it back in the same array?

I have an array of values generated by another part of my program. My goal is to count the number of occurences for each integer value in the array and put these values in a new array. This new array will be a histogram of the input array. My approach is to do auto-indexing with a for loop. In the loop I use a "index array" to get the current value of the histogram array and a "replace array subset" to update the array element with "current+1". The problem is that when I wire the output of the "replace array subset" VI back to its input, I get a wire error. I guess I cannot wire it like that, but what should I do? Is there a completely different approach to do this that
is more elegant?
Thanks for your help!
Benoit
0 Kudos
Message 1 of 9
(5,438 Views)
All sounds good until you wire the output of the "replace array subset" VI back to its input. At that point, could you simply feed your integer values into a totally new array using the "index array" VI? In fact, the elements stored into your new array could come directly off your initial array of values, where values checked for integer (using the "quotient & remainder" VI, where a remainder of 0 = integer) would be the integer elements for your new array. I'm sure there are many ways to do what your working on. Good Luck!
0 Kudos
Message 2 of 9
(5,437 Views)
Why not use the histogram.vi in functions>>mathmatics>>probability and statistics?
Message 3 of 9
(5,437 Views)
I did not even know there was a histogram function. I will try it soon. But I tried the shift register approach and it works fine. Thanks!
Benoit
0 Kudos
Message 5 of 9
(5,437 Views)
Hi Benoit,

I believe the thing that's missing is a shift register.

Right-click on the edge of your "For loop" and select add shift register.
Wire an initialized array to the shift register left terminal before entering the "for loop". Wire from this same terminal (inside the loop) as the source of the info used in your "index array" and replace array. The results of these two operations (just the way you are doing it now) gets wired to the "right terminal" of the shift register (inside the loop).

What ever you stuff into the right terminal, gets returned via the left terminal on the next iteration of the loop. When the loop is done, your final array of counts can be accessed by wiring from the "right terminal" (outside the loop).

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 9
(5,437 Views)
I spent some time yesterday trying the shift register approach and now it works perfectly! Thanks for the hint!
Benoit
0 Kudos
Message 6 of 9
(5,437 Views)
HI! I have quite the same problem... An Array should present how often a die fell on a special number. Array with 6 elements representing the 6 possible numbers. Came to the same problem with backwires. Havn't got into the shift register thing up to now. Maybe somebody could help me on that. And is there really no possibility to de- or increment a element of a Array directly?
maybe somebody could provide examples?
Thanks
0 Kudos
Message 7 of 9
(5,437 Views)
YOu must index out the previous count,
increment it
and use replace array element to put the updated value where it belongs.

Use your "die value" minus 1 as an index into your six element array.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 9
(5,437 Views)
Thanks.. somehow i got it to work.
ANDY
0 Kudos
Message 9 of 9
(5,438 Views)