LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to count particular occurrences in a matrix?

Solved!
Go to solution

I need to count the number of elements that are between 0 and 255 from a matrix.
I have attached my code but I don't know how to pass the count from the inner loop to the outer loop.

Can you help me with this? If there is a way to do this without loops, even better.

 

Thank you

0 Kudos
Message 1 of 11
(3,156 Views)
Solution
Accepted by topic author slovintern

Hi slov,

 

did you check the comparison functions palette? Did you notice the "InRangeAndCoerce" function?

 

check.png

(For large arrays with more than 32k "elements in range" you will need one extra step...

 

To answer your question:

Move that "0" constant outside the outer loop and the wiring will be much easier...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(3,148 Views)

Thank you. Haha didn't expect the reply this fast. I would have given you another one for the promptness. 
Hmm the maximum value I can get is 863168 so I'm guessing I need to use an extra step but I didn't understand where.
But I am getting some weird values though. Even negatives which should not be happening.
Any ideas why?

 

0 Kudos
Message 3 of 11
(3,139 Views)

If you're getting negatives i guess the U8 is overflowing? Add an U8 to I32 before the sum array.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 11
(3,134 Views)

The negative numbers problem seems to be resolved thank you but still gives unexpected values. ANything to do with the array size being 1920000?

0 Kudos
Message 5 of 11
(3,116 Views)

Hi slov,

 

show an example (maybe with a significant smaller array)!

Show the given result and tell us, what you expect...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 11
(3,108 Views)

@slovintern wrote:

The negative numbers problem seems to be resolved thank you but still gives unexpected values. ANything to do with the array size being 1920000?


As Gerd mention above, if array is bigger than 32k, you need 1 more step.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 11
(3,102 Views)

I'm sorry but I didn't understand what the extra step is

0 Kudos
Message 8 of 11
(3,083 Views)

Hi slov,

 

you didn't follow my question/suggestion from message #6. So how should we know, what you've done so far?

 

To explain your problem: The Sum function doesn't give the expected result because of an overflow due to an inappropriate datatype. You can check the datatype of a wire by moving the mouse pointer over the wire and looking at the context help. You already have been told how to convert that datatype and you already got a suggestion on which datatype to use...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 11
(3,080 Views)

Ah sorry looks fine now. I need to first acquire an image and then create the array from there.
The fault was during the acquisition. When I try it normally it looks fine. But I can't figure out the problem with the acquisition.
Can I ask you guys the question here or should I start a new thread?

0 Kudos
Message 10 of 11
(3,058 Views)