09-02-2019 05:04 AM
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...
09-02-2019 05:25 AM
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
09-02-2019 05:43 AM
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.
09-02-2019 06:04 AM
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.
09-02-2019 10:26 AM
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.
09-03-2019 08:16 AM
@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.
09-03-2019 09:50 AM - edited 09-03-2019 09:53 AM
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.)
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.