LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple array question

At least I think it is simple. I have been looking ta the NI example
'Stability of systems.vi' where a pole-zero model is inputed via the
front panel. This informaion (B(z)/A(z)) is given as a ratio of two
polynomials, the coefficients of which are entered via two arrays. I
wish to do likewise with my own .vi but I noticed that the example
starts off with the denominator polynomial having two coefficients (ie
one pole for A(z)) and I can quite easily increase this to any number by
entering them in the array from the front panel control array.. However,
if I wish to now go back down in oder from say 4 coefficients to 2 the
array stays at the same dimension (ie the largest that was entered). How
can I make an array be a specific dimension and then be
able to enter
the elements via the front panel? Obviously I can use Build array but
then how to get all the coefficients in without being clumsy and using
'Replace array element' one by one? If I just use an array as a control
on the front panel then its degree seems to be fixed by the largest
number of elements and cannot be reduced without re-starting the
program?

Tom
0 Kudos
Message 1 of 4
(2,877 Views)
There's a lot of ways to do this; here's the first one that came to my mind:

1. Create a drop-dwon menu you call Order and add all the order options you want available (or you could use just a numeric).

2. Create an array you call Coefficients. Hide the Index Display.

3. Create a property node of the array and select the "number of rows" or the "number of columns" property. Add 1 to the Order control's value and wire the result to this property. Now you have an array control that will resize to allow input of the correct number of coefficients.

4. If the array has been of a larger size previously you can either choose to ignore the coefficients not in use by code, or you can check the order value and reinitialize the array if the order changes (just wire
it to a shift register, check the value - if it has changed (there's a VI around that's called Change detector that is very nice to use for this, as an alternative), initialize an array of the correct size and write it to a local of the array control).

You can off course use separate controls instead of an array and just hide/show them depending on the order. The number of coefficients is not that big so you can use build array...but in cases where the arrays are large the best thing is to initialize an array of the right size and then use replace array elements. The replace function does accept array input by the way, you don't need to replace single elements (if you do, do it in a loop, or expand it (put the mouse pointer to the lower edge of the function's icon and scale it downwards...new terminals will appear as it scales) so that you get more than one index and element input).
0 Kudos
Message 2 of 4
(2,877 Views)
> if I wish to now go back down in oder from say 4 coefficients to 2 the
> array stays at the same dimension (ie the largest that was entered). How

I'm assuming that the arrays are always staying the same dimensionality,
1D, but that the size of the arrays need to be affected by the end user.

The built-in array has a way to do this, but it isn't the nicest thing
to teach the user of your VI. If you right click on the array, there
are menu items there to Empty the Array, and they you can grow the array
by typing into any element. Like I said, this is nice to use in
development, but not a nice interface when many people are using your panel.

Another way is to have a selector, like a ring or a slider that lists
off the number of coefficients. When the
value of this control changes,
read the value of the arrays, Resize to grow or shrink, then write back
to the arrays. If you want to, you can also affect how many elements
are visible so they won't see the grayed out elements, and you can hide
the index so the user won't put a coefficient in there and get confused.

Another comment is that some may prefer the data be put into a single 2D
array, kind of like a spreadsheet or matrix.

Greg McKaskle
0 Kudos
Message 3 of 4
(2,877 Views)
Greg McKaskle wrote:

> > if I wish to now go back down in oder from say 4 coefficients to 2 the
> > array stays at the same dimension (ie the largest that was entered). How
>
> I'm assuming that the arrays are always staying the same dimensionality,
> 1D, but that the size of the arrays need to be affected by the end user.
>
> The built-in array has a way to do this, but it isn't the nicest thing
> to teach the user of your VI. If you right click on the array, there
> are menu items there to Empty the Array, and they you can grow the array
> by typing into any element. Like I said, this is nice to use in
> development, but not a nice interface when many people are using your panel.
>
> Another way is to have a selector, like a ring or a slider that lists
> of
f the number of coefficients. When the value of this control changes,
> read the value of the arrays, Resize to grow or shrink, then write back
> to the arrays. If you want to, you can also affect how many elements
> are visible so they won't see the grayed out elements, and you can hide
> the index so the user won't put a coefficient in there and get confused.
>
> Another comment is that some may prefer the data be put into a single 2D
> array, kind of like a spreadsheet or matrix.
>
> Greg McKaskle

thanks both of you for these useful comments. I wil have a go!


Tom
0 Kudos
Message 4 of 4
(2,877 Views)