LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create array from loop but ignore some iterations

I have a problem creating an array from a loop.

In my case I am trying to parse a String into a 2D array.
Some fields in my data are invalid and I would like to ignore them. So I would like to use a case structure to check whether my data is valid and I can continue or if my data is invalid and I have to ignore this data.

In the attached picture you can see my try. I am struggling with the false case as in my understanding I would just leave it blank which causes an error because of the empty tunnel on the right 😞
0 Kudos
Message 1 of 4
(2,875 Views)
The case structure must produce an output from each case. To get what you want, try putting the output array of strings into a shift register. In the false case just pass the array unchanged. With this method you will not be able to use autoindexing on the loop. Use the Build Array function with the array from the shift register as the top input and the parsed element on the bottom. Initialize the shift register with an empty array.

If your arrays will get large, it is much faster to create an empty array of the size you will need (or the maximum you expect) and use the Replace Array Element function rather than Build Array. This avoids memory management problems where LV must reallocate memory for the array as it grows.

Lynn
0 Kudos
Message 2 of 4
(2,875 Views)
Thanx for that answer!

Now another Question 🙂
Is der any performance difference betweent BuildArray and the array creation via an indexed loop?
0 Kudos
Message 3 of 4
(2,875 Views)
Hi,


"FReAK La Marsch" wrote in message
news:50650000000500000018BB0100-1079395200000@exchange.ni.com...
> Thanx for that answer!
>
> Now another Question 🙂
> Is der any performance difference betweent BuildArray and the array
> creation via an indexed loop?

That would be practically the same. They are both relativelly slow (if the
array size gets big, e.g. 1M+).

Now that you have a shift register, try this to get some extra speed...

Wire an initialised array with the absolute maximum size. Instead of
building an array, replace the appropriate array element (keep track of the
element in another shift register, don't forget to initialize the shift
register). At the end of the loop, use Resize Array with the output of the
eleme
nt shift register, and your array is nicelly cut to the appropriate
size.

Regards,

Wiebe.
0 Kudos
Message 4 of 4
(2,875 Views)