LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Selective Array Averaging

Solved!
Go to solution

Hello,

 

I have a 2D Array. The code below generates a random 3x3 Array. 

 

I want to average (or obtain the mean) of only the values above a defined value (user defined) in the array.

 

Could someone help me.

 

I've tried to use a "greater than" type case statement, but when I do that, for elements below the defined value a zero is placed into a new array. This alters the the average as it includes the zero as an element.

 

I almost need to create a new 1D array of just elements above the define value from the 3x3 array.

 

I wish to adapt from what I learn here to much larger arrays 400x400 and up.

 

Any help would be much appreciated.

 

Thanks

 

0 Kudos
Message 1 of 9
(3,450 Views)

See attached example. Note that this algorithm is "brute force" and not optimized for speed or memory usage.

It simply iterates through the 2D array and builds a new 1D array with values above the threshold. This array is then used for analysis.

 

hope this helps,

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 9
(3,436 Views)

Hi Kamilan,

 

a possible solution could be to replace all values below your threshold with NaN (instead of zero), then call the standard mean function...

Best regards,
GerdW


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

Hi,

 

I had prepared this earlier but didnt have time to post before going to a meeting. The works done so here it is anyway.

 

There is a way to do it using array arithmetic so it should be pretty quick for you larger array.

 

 

However, I agree with Gerd's method as you could other functions like StDev if you need it

 

cheers

 

David

 

PS: I just noticed that you could using the Coerced? output to get the number of elements below threshold instead of the >= threshold code at the bottom.

Message Edited by David Crawford on 12-08-2009 11:53 AM
Message Edited by David Crawford on 12-08-2009 11:55 AM
Download All
Message 4 of 9
(3,415 Views)

Hi David,

 

as the OP said "much larger arrays" I prefer solutions which are inplace-ready Smiley Wink

 

Your solution will create array copies (coerce, >=, boolean to number) with possible problems later on...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 9
(3,409 Views)

Gerd,

 

i don't get what you intend with this answer. The reason are the following issues:

a) standard mean function only works with 1D arrays (or am i mistaken here?)

b) as far as i know, the "standard" mean also sums up the whole array. Summing up an array containing an NaN will always result NaN as well. What is the mean of NaN??

 

Please don't take this post as an offence, i just wondered about your answer and tried some things the attached VI shows....

 

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 9
(3,405 Views)

Hi Norbert,

 

I must apologize, should check my messages before posting...

 

I thought Mean.vi would also take 2D arrays - seems I made a wrapper vi long time ago for this use case.

I also thought Mean.vi would omit NaN values when calculating the average - second fault...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 9
(3,400 Views)

Hello,

 

David Crawford - Thank you for your code. I do not wish to change the values to the coerced value. However, you have introduced me to another function block that I was unaware to and thank you for that. 

 

Unfortunately , I am using LabVIEW 8.6. Please Norbert B, could you please repost the vi.

 

Thank You

 

Kamilan  

0 Kudos
Message 8 of 9
(3,373 Views)
Solution
Accepted by topic author Kamilan

Attached in LV 8.6. Please note that i did not downconvert the other example since it is imho to no avail for you.

 

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 9 of 9
(3,351 Views)