From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Print series of number after pre-determined iteration

Hello everyone,

 

I am working on a project where I have for-loop inside a while-loop which iterates continuously until I stop the while loop. 

I want to create an array of elements in the below fashion, 

for the first 300 iterations (0-299), I need the array elements to be 1 and 2 for next 300 iterations (i.e. 300-599).

Likewise, I want to create an array of elements from 1 to 20. 

can anyone help me with this?

 

Thanks and regards,

VigViv

0 Kudos
Message 1 of 9
(1,619 Views)

Hi VigViv,

 


@VigViv wrote:

I want to create an array of elements in the below fashion, 

for the first 300 iterations (0-299), I need the array elements to be 1 and 2 for next 300 iterations (i.e. 300-599).

Likewise, I want to create an array of elements from 1 to 20. 


Do those iteration counts refer to the While loop? Or to the (inner) FOR loop?

Why do you need a FOR loop, when you could use InitArray to create an array?

What have you tried so far? Where are you stuck?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(1,615 Views)

Hi GerdW,

 

No, the iteration count refers the for loop. 

I figured it out. Anyways, thanks for your quick reply. 🙂 

I am attaching the screenshot of the logic I used for future reference. 

 

Thanks and best regards,

VigViv

0 Kudos
Message 3 of 9
(1,608 Views)

Hi VigViv,

 

suggestions:

  • with a limited set of (fixed) ranges you could use just one case structure instead of this pile of comparisons/select functions
  • with a larger set of (variable) ranges you could use array functions to select an output value based on an input value…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 9
(1,579 Views)

@VigViv wrote:

No, the iteration count refers the for loop. 

I figured it out. Anyways, thanks for your quick reply. 🙂 

I am attaching the screenshot of the logic I used for future reference. 

altenbach_0-1606925324675.png

 


 

This code makes absolutely no sense because you are constantly re-doing work you already did in previous iterations of the while loop. All you need to do is retain the current array in a shift register and append one (!!) new element per itations of the while loop. The FOR loop is not needed. Ultimately you'll run out of memory, of course.

 

Also, next time please attach your VI. Pictures are useless for debugging.

 

I think the following would do about the same, but there are plenty of other ways to do this.

 

altenbach_0-1606926339938.png

 

0 Kudos
Message 5 of 9
(1,559 Views)

@VigViv wrote:

I want to create an array of elements in the below fashion, 

for the first 300 iterations (0-299), I need the array elements to be 1 and 2 for next 300 iterations (i.e. 300-599).

Likewise, I want to create an array of elements from 1 to 20. 

 


See if this gives you some ideas. If you want all the intermediary shorter arrays, place the indicator and wait inside the loop.

 

altenbach_0-1606928008381.png

 

0 Kudos
Message 6 of 9
(1,549 Views)

If you are only interested in the final array, this would also work. (Note the concatenating output tunnel)

 

altenbach_0-1606928345354.png

 

0 Kudos
Message 7 of 9
(1,545 Views)

Hi Altenbach, 

Thanks for your message. I can definitely use one of your solution.

 

Best regards,

VigViv

0 Kudos
Message 8 of 9
(1,512 Views)

Hi GerdW,

 

Thanks for your suggestions. I will definitely consider those.

 

Best regards,

Vignesh

0 Kudos
Message 9 of 9
(1,509 Views)