LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variable array size in labview

Solved!
Go to solution
Highlighted

Hi,

I want to give a series of integers (1-D array) to the for-loop. but the number of integers (array size) can vary each time depending on the user. While I tried accomplishing this using a 1-D array, I found it was difficult to decrease the array size. For example, let say, the input array had 4 elements for my first run, then for the next run, I only need 2 (first two) elements, the program would still take 4 elements. Is there any other way to achieve variable array sizing?

0 Kudos
Message 1 of 8
(208 Views)

Hi Jena,

 


@SanjoyJena wrote:

For example, let say, the input array had 4 elements for my first run, then for the next run, I only need 2 (first two) elements, the program would still take 4 elements. Is there any other way to achieve variable array sizing?


You already use autoindexing at the loop borders, so the FOR loop will try to process all array elements. When you want to process less elements as are provided by the input array you need to set the loop count ("N" terminal of the loop)…

Best regards,
GerdW
CLAD expired, using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

0 Kudos
Message 2 of 8
(201 Views)
Solution
Accepted by topic author SanjoyJena

@SanjoyJena wrote:
For example, let say, the input array had 4 elements for my first run, then for the next run, I only need 2 (first two) elements, the program would still take 4 elements. Is there any other way to achieve variable array sizing?

So you just need to resize the input array to 2 values?  You can right-click and delete elements on the front panel.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 3 of 8
(136 Views)

As has been suggested, wiring the "N" terminal/node at the top left of the For loop (from the outside) will add an additional limit to the number of elements. You could wire this to a(n additional) control if desired.

It's important to realize that the total number of iterations for a For loop is the minimum of all of the possible limits/conditions it has. So, for example, with 2 array inputs set to autoindex and a value wired to N, the last value of "i" will be one less than the smallest of the two array sizes or the N terminal (one less because it starts from 0).

 

If you want to reduce the size of your array before reaching the For loop for some reason (or your real code doesn't need a For loop) you could use Array Subset.

 

 


GCentral
0 Kudos
Message 4 of 8
(124 Views)

Hi GerdW,

I wish to put 1 D array of variable size as input. The main problem is in the input array, once the input array size is increased (by feeding 4 elements), the array size cannot be decreased for next run using same input array. Suppose for next run, I need to feed only 3 elements, the 4th once does not get automatically disabled like 5,6,7th ......N elements. 

0 Kudos
Message 5 of 8
(105 Views)

Actually this works. Smiley Happy Is there a better way of doing this without having to resort to deleting element or can the "delete" be put on the front panel. The program is meant to be used by first timers. I will realy appreciate it if you can tell me the way to put delete in the front panel or make this process of resizing/adding/deleting  more user friendly. 

0 Kudos
Message 6 of 8
(103 Views)

Hi cButcher,

I agree with you. the method is by the book and is correct but not user-friendly. A new user might not know what and where to change. 

0 Kudos
Message 7 of 8
(101 Views)

I'm a little confused by (and perhaps others are too) how you want this program to be used.

 

You have an Array control on the front panel. Each time you run this program, you want the user to set some specific data values. You want to be able to remove old data, by the sounds of it.

 

Do you need to retain any of the input data (after the previous run)?

If not,you could try something like the following:

Example_VI_BD.png

Note this is more or less solving your problem with a sledgehammer, and will be frustrating if you want to enter the same values over and over... but without more information it's the first that comes to mind.

 

If you give a bit more detail about the desired workflow etc, it might be possible to suggest a better method.


GCentral
0 Kudos
Message 8 of 8
(91 Views)