Showing results for 
Search instead for 
Did you mean: 

Dynamic array

Hello all,


I'm reading the temperature from a thermometer with labview in a loop, in a way that I get a reading each X seconds. In order to make some verification to the data read I would like to compare the current reading with the ones from the last couple of hours. To achieve this I was thinking about building a array in which I would store my last N readings. The array would have 0 length in the start of the program, grow up to N and keep that size indefinitely. So, when a new measurments enters in labview it should be placed in the last position of the array, making the older element (0 index in array) to drop out. This way I could compare my current reading with a fixed amount of previous reading.


Someone has any idea how to achieve this in Labview?


Thank you all in advance

0 Kudos
Message 1 of 3

You do not really want a dynamic array because of memory allocation issues.  For small N you can get away with it but for large N the performance can deteriorate substantially.


The better way to do this is to initialize an array with N elements.  Use the Initialize Array primitive in the Array palette outside the loop.  Make the data value NaN if you are using DBL data type or a value outside the range of your system if you are using integers.  Then inside the loop where you acquire the data use Replace Array Subset.  One of the NaN values is replaced by the current measured temperature.  Use a shift register to keep track of the index.  When the index reaches N-1, reset to 0 and continue.  This will produce the circular buffer effect.  After the array is filled the first time the index "k" in the shift register will point ot the oldest data point and "k-1" has the newest.



Message 2 of 3

Or, just use a queue. It can be set to have a max size.

Message 3 of 3