LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I count occurances in an array

I have a 2D array of strings and I want to count the number of times a particular word occurs in the array. I have been able to isolate the column that contains the string I want to count but I can't seem to get the code to actually count how many times that word shows up.
 
Any ideas? Code attached.
 
Tay


Message Edited by slipstick on 04-22-2008 11:34 AM
0 Kudos
Message 1 of 11
(24,280 Views)
Well, your code doesn't really do anything.

Tip: Take a look at these functions:
  • Equal?
  • Boolean To (0,1)
  • And Array Elements
Shouldn't be too hard to figure out from there. Smiley Wink

Note: This assumes case sensitivity. If you want case insensitive, then use "To Lower Case" or "To Upper Case" as well.
Note2: In case you try to use them, you don't need any loops.


Message Edited by smercurio_fc on 04-22-2008 11:39 AM
Message 2 of 11
(24,270 Views)
Here is a quick example, unfortunately it relies on the user being able to correctly enter the word to search for.

Cheers






Message Edited by jmcbee on 04-22-2008 10:43 AM
Message 3 of 11
(24,261 Views)
Well, no it doesn't. The part that would do any work I can't get to, so I didn't include it. I am looking at your suggestions. I keep forgetting that the comparisons palette isn't only for numbers. Newer guy here.Smiley Very Happy
0 Kudos
Message 4 of 11
(24,252 Views)
Here is one without any loops.
Message 5 of 11
(24,248 Views)
Well, I see that someone read my tips. Smiley Very Happy
0 Kudos
Message 6 of 11
(24,241 Views)

Ah! I didn't know of the function of 'add array elements'! All is clearer now. Thanks!

 

Tay

0 Kudos
Message 7 of 11
(24,233 Views)
The tips provided by smercurio will work if the search word is exactly one whole element of the array. If you want to find "None" in the string "None of the Above" using Equals? will not work. Similarly if the search word can occur more than once in an element and you want to know the number of occurrences of the word rather than the number of elements, you cannot use Equals? The Match Pattern function from the strings palette would be used in a loop with a comparison on the offset past match output and a case structure to count the occurrences.

Lynn
Message 8 of 11
(24,212 Views)

Fortunately, I control the output of the program creating the file I am reading, and it will always be the whole element.Smiley Happy

Tay

0 Kudos
Message 9 of 11
(24,186 Views)

These examples are so much more helpful if you turn on the labels before doing the screen capture.  I have attached the "No Loops" technique showing labels. It took me almost half an hour to figure them out.

 

Seriously, most of us don't memorize all the little icons and cannot identify the more exotic ones.

Message 10 of 11
(23,148 Views)