10-21-2019 05:08 AM
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?
Solved! Go to Solution.
10-21-2019 05:11 AM
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)…
10-21-2019 09:16 AM
@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.
10-21-2019 09:32 AM
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.
10-21-2019 10:37 AM
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.
10-21-2019 10:45 AM
Actually this works. 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.
10-21-2019 10:48 AM
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.
10-21-2019 11:11 AM
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:
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.