# LabVIEW

cancel
Showing results 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 .

Message 1 of 10
(1,251 Views)

## Re: Labview basic count question.

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.

Message 2 of 10
(1,219 Views)

## Re: Labview basic count question.

@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.

Message 3 of 10
(1,218 Views)

## Re: Labview basic count question.

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,197 Views)

## Re: Labview basic count question.

@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...

Message 5 of 10
(1,174 Views)

## Re: Labview basic count question.

@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...

Or this:

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

## Re: Labview basic count question.

@paul_cardinale wrote:

Or this:

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.

(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!)

Message 7 of 10
(1,063 Views)

## Re: Labview basic count question.

@altenbach wrote:

@paul_cardinale wrote:

Or this:

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.

Message 8 of 10
(878 Views)

## Re: Labview basic count question.

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).

Message 9 of 10
(867 Views)

## Re: Labview basic count question.

@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).

Have you thought of rolling a generalized one?

Message 10 of 10
(854 Views)