LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating the mean of an array subset

Hi,

I am trying to figure out how to get numbers into an array and doing some mathematical manipulations on that array.

Attached is my subVI. I have two values going into it (pressure and warning_pressure). The pressure values are real-time from a cDAQ device and the warning_pressure is a user defined value. I would like to stream (as an example) 7200 values into my array and then take a subset out (100 values and average them) of values 'now' and a subset of 100 values from 'before' and do some calculation on them.

if I do not index when I insert into array, does it not append to the end but it looks like it is just overwriting the last value and sticking it in the last element.

is there a way to add values to an array, sticking them in the last element and then appending until n=0 and then it will just keep doing that?

I would like my main vi to be controlled by a stop button that the user clicks on and not by loop iterations.

 

Cheers...

0 Kudos
Message 1 of 7
(2,512 Views)

If you just want to add to the end of an array i'd use Build array (you might need to r-click to choose concatenate). To get the last 100 values simple use Array Size -100 and wire to Get Array subset.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 7
(2,492 Views)

Please find attached. I took out the 'insert into array' and added a 'build array', choosing to concatenate inputs.

The values are all going into the last array element, over-writing the prior value, not sticking the prior value into n-1.

0 Kudos
Message 3 of 7
(2,471 Views)

Don't use the local variable.  You are creating a race condition.  Wire a simple wire instead.

 

But where is it that you are collecting the data?  It seems to me that you should be able to get all of your data in a single read, depending on your sample rate.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(2,455 Views)

Look at mean point by point function

If you are building array, you are constantly reallocating memory. It is more efficient to dedicate memory once, then replace elements.

 

0 Kudos
Message 5 of 7
(2,408 Views)

@Alexander_Sobolev wrote:

Look at mean point by point function

If you are building array, you are constantly reallocating memory. It is more efficient to dedicate memory once, then replace elements.

 


Not quite true, i don't know the exact value, but it works similar to Java; when an array is created it allocates e.g. 50 slots, and each time the array gets 'full' it doubles in size. In some instances this difference can make a big difference, but usually not.

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

Qestit Systems
Certified-LabVIEW-Developer
Message 6 of 7
(2,365 Views)

Please do NOT change the diagram background color, it makes things hard to see. (If you have problems with glare, adjust the screen brightness or see an ophthalmologist. You might have cataract).

 

All you need is a fixed-size history buffer of the last 200 elements, no need to "grow anything" without bounds. Right? You could even use two ptbypt means (100pts), one after a -100 z-transform delay. (you need to decide when the values become valid and how you want to initialize.)

 

ztransform.png

 

As others have said, you misuse of local variables for no reason create race conditions and irreproducible behavior. If there is no wired dependency, execution order is not predictable. This is a serious mistake and I recommend you go back to the tutorials before continuing.

 

racecondition.png

 

 

0 Kudos
Message 7 of 7
(2,345 Views)