LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Count number of occurrences in a table

I am a newbie at Labview.  I am trying to write something simple where to count up number of occurrences in a table.  From excel to be exact.
 
For example...
 
1
1
1
2
2
3
 
I want the answer 1 = 3 , 2 = 2, 3 = 1.
 
Can someone help?  Also... I am using labview 7.


Message Edited by Sendtohen on 12-14-2007 02:56 PM
0 Kudos
Message 1 of 8
(5,311 Views)
Hello,

Attached is a little vi that will take in an array of numbers, like your example...

1
1
1
2
2
3

and return the answer you are looking for.  Unfortunately the vi is in 8.2 as I do not have version 7.x.  Perhaps someone will be able to convert it for you.

Cheers!


Message Edited by jmcbee on 12-14-2007 03:17 PM
0 Kudos
Message 2 of 8
(5,287 Views)

Here is an image of the block diagram to get you started.  This program also assumes that you have read the excel file into labview and have created a 1D array of I32 values out of the data.

-Cheers!


Message Edited by jmcbee on 12-14-2007 03:11 PM

Message Edited by jmcbee on 12-14-2007 03:16 PM

Message Edited by jmcbee on 12-14-2007 03:16 PM

Message Edited by jmcbee on 12-14-2007 03:18 PM
0 Kudos
Message 3 of 8
(5,285 Views)
Or you can replace all these "insert into array" with plain "built array" nodes. Same result!
 
Advantages:
  1. Simpler, more compact, and easier to read code.
  2. No need to keep track of insert points, eliminating a shift register.

It can probably be simplified even more.

(TRUE case just does a +1 on the lower shift register wire.)



Message Edited by altenbach on 12-14-2007 06:08 PM
Message 4 of 8
(5,261 Views)
altenbach,

Does "insert into array" create a copy of the data the same way that "build array" does?  I was trying to avoid doing this in a loop, but perhaps "insert into array" does it anyhow. 

Cheers!
0 Kudos
Message 5 of 8
(5,217 Views)
They both need to make a copy because the size of the array changes. None have an advantage.
 
So yes, for huge arrays there are probably tweaks that could be done to optimize the code for speed and operate more in-place. 🙂
 
The sorting is about O(NlogN), so will be dominant for large arrays because all the other stuff is O(N). If we expect most elements to be different, we could just preallocate the final array dimension the same as the input array (worst case scenario, all elements different!) and then use "replace array subset" to fill with data, followed by a final trimming to the actual size. We could also do a quick "run" through the array and count the number of transitions, then preallocate the output array at the correct size before doing the statistics. This might be better for cases where the final output is significantly smaller than the input (=many duplicate elements). There are many possibilities. 😄
 
For smaller arrays, the given code should be fine.
0 Kudos
Message 6 of 8
(5,210 Views)
I want to thank everyone for the help.
 
0 Kudos
Message 7 of 8
(5,193 Views)
I want to thank everyone for the help.
 
0 Kudos
Message 8 of 8
(5,192 Views)