LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview basic count question.

I have a 1d array containing 1,2,3,4,5,6 numbers which are repeated n no of times .i want to count no of occurances of each element in labview using search 1d array palette .

0 Kudos
Message 1 of 10
(1,623 Views)

This kind of sounds like a homework assignment that you're posting and hoping we'll solve for you.

 

Have you even tried?  If you post something that looks like you tried (screenshot, VI file, even a description of what you tried) but failed we may help point you in the right direction.  We're fine with helping you actually learn. 

 

If you just want someone to do your homework for you, this isn't the place for that.

0 Kudos
Message 2 of 10
(1,591 Views)

@qwaefxbnhhjugyjv wrote:

I have a 1d array containing 1,2,3,4,5,6 numbers which are repeated n no of times .i want to count no of occurances of each element in labview using search 1d array palette .


You should not tell us what to use (e.g. "search 1D array") because there are probably much better tools. I would probably use a map in the general case. (Maybe the bottom of slide #37 here can give you some ideas.).

 

However, if these are really all small positive integers, all you need is an array of counts where the index is the value. Keep it in a shift register and iterate over your input in a FOR loop.

 

0 Kudos
Message 3 of 10
(1,590 Views)

Perhaps a histogram function would serve you.

"If you weren't supposed to push it, it wouldn't be a button."
Message 4 of 10
(1,569 Views)

@altenbach wrote:

However, if these are really all small positive integers, all you need is an array of counts where the index is the value. Keep it in a shift register and iterate over your input in a FOR loop.

See if you can reproduce this...

 

altenbach_0-1708719888840.png

 

0 Kudos
Message 5 of 10
(1,546 Views)

@altenbach wrote:

@altenbach wrote:

However, if these are really all small positive integers, all you need is an array of counts where the index is the value. Keep it in a shift register and iterate over your input in a FOR loop.

See if you can reproduce this...

 

altenbach_0-1708719888840.png

 


Or this:

h6.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 10
(1,527 Views)

@paul_cardinale wrote:


Or this:

h6.png


Did you actually run this and look at the x-values of the histogram???? (Hint: they are not integers!)

 

With some of playing, you can get it to work using the General Histogram.

altenbach_0-1708752135960.png

 

(Histograms are for floating point values, and are not the right tool for discrete small non-negative integer stuff. And if the values are a collection of gigantic integers over the full range of potential values, we would use a map as mentioned already!)

 

 

0 Kudos
Message 7 of 10
(1,435 Views)

@altenbach wrote:

@paul_cardinale wrote:


Or this:

h6.png


Did you actually run this and look at the x-values of the histogram???? (Hint: they are not integers!)

 

 


That surprised me.  Thanks for the edification.

0 Kudos
Message 8 of 10
(1,250 Views)

I have never in my life found any use for the built-in histograms and always roll my own. They are ancient and clumsy. Why would we need all these redundant outputs if we can just unbundle the xy graph data to get the others?

 

Many times I define my bins according to the requirements, then increment the two closest bins proportionally to the fractional position between the bins. This guarantees that the median of the distribution is retained exactly, even for coarse bins.

 

For example if the value is exactly in the middle, I increment that bin, but if the value is right at the border between two bins, I fill two adjacent bins equally. Any other scenario proportionally. Here are three examples of what's added as a function of value (red arrow).

 

altenbach_0-1708792348213.png

 

 

 

0 Kudos
Message 9 of 10
(1,239 Views)

@altenbach wrote:

I have never in my life found any use for the built-in histograms and always roll my own. They are ancient and clumsy. Why would we need all these redundant outputs if we can just unbundle the xy graph data to get the others?

 

Many times I define my bins according to the requirements, then increment the two closest bins proportionally to the fractional position between the bins. This guarantees that the median of the distribution is retained exactly, even for coarse bins.

 

For example if the value is exactly in the middle, I increment that bin, but if the value is right at the border between two bins, I fill two adjacent bins equally. Any other scenario proportionally. Here are three examples of what's added as a function of value (red arrow).

 

altenbach_0-1708792348213.png

 

 

 


Have you thought of rolling a generalized one?

0 Kudos
Message 10 of 10
(1,226 Views)