From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find maximum occurance of a number in numeric array

I trouble to debug my code.here I attached my file. Kindly help me to get correct output.
0 Kudos
Message 1 of 9
(2,514 Views)

Based on your code, I'm guessing you're trying to count each value in the array?

 

If you're using LabVIEW 2019, this is a perfect application for a Map.

If not, you can do the same using Variant Attributes.

 

You want some key (the value of the "array 2" element) and then a value (the number of times it appears).

You can get the value by adding one each time, as you are currently doing (although consider the use of In-Place Element Structure with Index/Replace Array Element if not changing to Var Attribs or Map, either of which will use the same In-Place Element Structure but with different nodes).

 

An example is below (is this what you're trying to do?)

Count occurrences of each valueCount occurrences of each value


GCentral
Message 2 of 9
(2,500 Views)

There's also the Unique Numbers and Multiplicity.vi, found in the Mathematics->Polynomial palette. It'll give you an array of all of the unique numbers from the input array, and an array of how many times each of those numbers appears in the input array.

 

Edit: Open up that VI and see how it works, and compare it to your own VI. Your approach looks pretty similar.




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
Message 3 of 9
(2,467 Views)

@MichaelBalzer wrote:

There's also the Unique Numbers and Multiplicity.vi, found in the Mathematics->Polynomial palette.


I knew there'd be a built in version somewhere...


GCentral
Message 4 of 9
(2,460 Views)

Let me see.... Hmmm. are you trying to find the MODE of the input array?  Why, Yes you are!

Mode.png


"Should be" isn't "Is" -Jay
Message 5 of 9
(2,429 Views)

@JÞB wrote:

Let me see.... Hmmm. are you trying to find the MODE of the input array?  Why, Yes you are!

Mode.png


This is very straightforward, but it doesn't give the number of occurrences. Still not exactly sure what the OP wants, but good to have another tool in the toolbox!


GCentral
0 Kudos
Message 6 of 9
(2,410 Views)

Can you please share the link of this VI,it's exactly what i needed.

0 Kudos
Message 7 of 9
(359 Views)

ceuca.ioana7@gmail.com wrote:

Can you please share the link of this VI,it's exactly what i needed.


 

All code above are actually LabVIEW snippets and already contain all code.

 

(personally, I would probably use a map instead. 😄 )

0 Kudos
Message 8 of 9
(339 Views)

@altenbach wrote:
(personally, I would probably use a map instead. 😄 )

For example as follows:

 

(this is not a snippet, so try to recreate it. Most is in the collection palette, requires LabVIEW 2019 or newer. Watch my presentation for details)

 

I intentionally made the values integer, because equal comparison with DBL are potentially problematic.

 

altenbach_0-1706480644908.png

 

Message 9 of 9
(333 Views)