LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Friday grumpiness: mode.vi

Input 1, 2, 2, 2, 3, 5 into mode.vi, mode =... 3.  Off to the help files!

Does a (erm, how to say this) more rigorous numeric mode function (most common occurrence in the array) exist in LV?  As opposed to the histogram based mode function in mode.vi?

I can write the simplistic code bit if it doesn't (and add to codebase, distribute to developers, and check existing codebase for misused mode.vi Smiley Mad)


Don't mind me folks, I just hate surprises on Friday Smiley Tongue

0 Kudos
Message 1 of 12
(3,800 Views)
The mode VI should be fine for what you want.
 
By default the bin size is only one and since the VI averages the contents of the most common bin you get 2.5 (which rounds to 3).  Instead get the size of your array and wire this to change the bin size.  Since the number of bins now equals the size of the array it will find the most (in your case three 2s) and averaging this bin still results in a 2.
 
See picture:
 
0 Kudos
Message 2 of 12
(3,784 Views)
The Mode VI works on DBL numbers, you seem to look for an pure integer version. 😉
 
In real-world DBL data, it is very unlikely that two values are ever the same, so a true mode will never give any meaningful data. Mode only works if the data is quantized to a manageable set of possibilities. Wire an "intervals" input large enough (depends on the range of values and desired precision). 🙂
Message 3 of 12
(3,785 Views)
Chaos,

I tried it.  Check out the attached VI (7.1) for a reduced example.

Input = array of integers, mode = 15.14.
0 Kudos
Message 4 of 12
(3,780 Views)
altenbach,

Oh, I understand the reasoning, and approve of it wholeheartedly.  However, the name of the function could have been more descriptive, or a boolean switch between histogram mode and true mode could have been included, or the behavior could have been made polymorphic... any of a number of solutions (particularly the name) would have saved me some time.

I just hate surprises.  My poor sales rep puts up with hearing about a public NI-published bug list every time she has the misfortune to wander across my company Smiley Very Happy
0 Kudos
Message 5 of 12
(3,774 Views)
Doh, ok thats not how I thought the VI read in the help file.
My bad.  In that case how about this?
 
See picture:
 
Message 6 of 12
(3,766 Views)
Ah, now that is magnificent!  Exactly what I was looking for.

Thanks!
0 Kudos
Message 7 of 12
(3,760 Views)
Man I hate Fridays... I just cant seem to think right for some odd reason.  I guess my brains already on the back 9 Smiley Very Happy
 
Anyways I think the one I posted above has a bug in it.
I played around some more and this is what I came up with.  Its possible you noticed the same thing and already changed yours but just in case you have not...
 
 
0 Kudos
Message 8 of 12
(3,737 Views)

Chaos,

Are you sure "Unique Numbers and Multiplicity" is available in LabVIEW 7.1? I cannot find it.

0 Kudos
Message 9 of 12
(3,708 Views)
It is under the mathematics pallette>>under polynomial.
 
 
BJD1613

Lead Test Tools Development Engineer

Philips Respironics

Certified LV Architect / Instructor
0 Kudos
Message 10 of 12
(3,623 Views)