LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a Dynamic Array

I've been trying to come up with a way to make a dynamic array in LV 6.i so that it's always the exact size to match the data. The way I do it now is to just initialize a huge array like 1000x2 and set everything to zero. Then I use Replace Array to fill in as needed and leave the rest at 0. This works, but takes a long time to execute, isn't guaranteed to be able to manage every data point, and leaves a "ghost plot" at the initial value for the left-over 0's. I'm also not really a pro at using clusters, so if there is a way to do it and keep everything as an array, that'd be ideal. Even better yet, if someone already has a sample .vi made that does this and wants to attach it, by all means...
Thanks
p.s.
Thanks to everyon
e who answers questions on here and does so, so quickly. You make this site an invaluable resource.
0 Kudos
Message 1 of 5
(3,224 Views)
Have a look at 'Smart Buffer (DBL).vi' (you find it in folder
examples/general/globals.llb/Smart Buffer (DBL).vi).
It allows to add one data at a time and read one at a time (but not from
random positions). To get that behavior you have to modify it quite a bit,
but stil the VI is a good starting point. Of course you can also modify
it to take other data types than DBL.

The problem of the 0 values in your case can be avoided by putting NaN
('Not a number') values in the array. These are simply not plotted


-Franz



Adam_J schrieb:

> I've been trying to come up with a way to make a dynamic array in LV
> 6.i so that it's always the exact size to match the data. The way I
> do it now is to just initialize a huge array like 1000x2 and set
> everything to ze
ro. Then I use Replace Array to fill in as needed and
> leave the rest at 0. This works, but takes a long time to execute,
> isn't guaranteed to be able to manage every data point, and leaves a
> "ghost plot" at the initial value for the left-over 0's. I'm also not
> really a pro at using clusters, so if there is a way to do it and keep
> everything as an array, that'd be ideal. Even better yet, if someone
> already has a sample .vi made that does this and wants to attach it,
> by all means...
> Thanks
> p.s.
> Thanks to everyone who answers questions on here and does so, so
> quickly. You make this site an invaluable resource.
0 Kudos
Message 2 of 5
(3,224 Views)
Hi everyone,

Maybe I`m missing the point here or stating something really stupid but
don`r arrays automatically re-size with the data in them? All you need is
to append new data to an existing array and it will grow to accomodate these
data. Since you don`t have any "extra" points after your data, the ghost
points disappear.

I don`t see the problem if all that is needed is that the array "fits" the
data. If you want it to fit and be a fixed size, that`s different, but
these are two very different problems.

Hope this helps (and isn`t overlooking something obvious)

Shane
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 5
(3,224 Views)
I guess you are right. At least now, today, with LV 6, the automatic array
resizing when values are added is much faster than in early LV versions like 2.x
or 3.x. With those versions it was MUCH faster to use strategies, where an array
grew in chunks, not element by element.

Now with LV 6 (or LV 5 already?) NI introduced a more clever memory management
and probably the VI I suggested is too complicated a solution (I just remembered
the old days only...).

But still, for VERY LARGE arrays, an intelligent array resizing might be better.
You can also create an array/buffer that way which shrinks when needed. That's
of course not possible with the built in array append functionality.


-Franz

Shane schrieb:

> Hi everyone,
>
> Maybe I`m missin
g the point here or stating something really stupid but
> don`r arrays automatically re-size with the data in them? All you need is
> to append new data to an existing array and it will grow to accomodate these
> data. Since you don`t have any "extra" points after your data, the ghost
> points disappear.
>
> I don`t see the problem if all that is needed is that the array "fits" the
> data. If you want it to fit and be a fixed size, that`s different, but
> these are two very different problems.
>
> Hope this helps (and isn`t overlooking something obvious)
>
> Shane
0 Kudos
Message 5 of 5
(3,224 Views)
Hi Adam,
let me see if I understood your problem:
you want to add an undefined number of data in a 2D array and want that its size corresponds always to the number of data inserted, right?
The solution you use works fine but has a drawback which is the amount of memory you use. If you don't insert 1000 1D array, part of the memory LV allocates to contain your 1000x2 array is useless.
LabVIEW has the capability of auto-sizing an array automatically according to the data inserted by the function Build Array.
I attach a simple vi that inserts random DBL data in an initially empty 2D array each time you hit the button INSERT. You can see that its size updates automatically.
In LV 6 you can also use the function Insert Into Array.

Good luck,
Alberto
Message 3 of 5
(3,224 Views)