LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Swap order nested loop

Hi,

 

I am a LabVIEW user for some years now, yet sometimes I still get stuck in the most basic things. I attach a simplified version of my problem: in this VI, there are two nested for loops. The code works fine, where the small loop runs to completion and then the bigger loop continues.

 

What I want to is to swap the order. Skipping all the details - I want/need to keep the loops as they are in the block diagram, but have the bigger loop run first.

 

To summerize, for i small loop and j big loop:

 

DEFAULT:
{i,j}={1,1}, {2,1}, ...{imax,1},{1,2}, {2,2}, ...{imax,2}, ...{1,jmax}, {2,jmax}, {imax,jmax} 

 

I WANT:

{i,j}={1,1}, {1,2}, ...{1,jmax},{2,1}, {2,2}, ...{2,jmax}, ...{imax,1}, {imax,2}, {imax,jmax} 

 

Furthermore, it would be great if I can switch between the two configurations with a boolean. Thanks so much in advance!

 

0 Kudos
Message 1 of 10
(2,173 Views)

(Your two controls have the wrong representation.)

Can you make a more reasonable example that demonstrates your actual usage better. Right now it completes in nanoseconds, only showing the max i,j at the end.

 

Do you want 2D array output with two columns? Do you need to process two values during execution of the loops?

 

0 Kudos
Message 2 of 10
(2,156 Views)

Maybe all you really need is one loop?

 

altenbach_0-1651184106939.png

 

0 Kudos
Message 3 of 10
(2,147 Views)

Hi altenbach,

 

Thanks for your answer.The program completes in nanoseconds sure, I forgot to say to ¨highlight execution¨. I send another VI. 

 

 

Do you want 2D array output with two columns? Do you need to process two values during execution of the loops?

So basically it would be convenient for me to keep the two for loops as they are, because there is a lot of code that it would be tiresome to move around (since LabVIEW is graphical). I don´t need a 2D array with two columns and I don´t quite follow the ¨process two values¨.

Maybe I can summorize in a sentence what I want. My inner loop runs an experiment and saves the data, so it saves data like Scan 1, Scan 2,...etc. My outter loop makes a background ¨b¨ measurement, so it runs the experiment and saves data like Scan 1b, Scan 2b, ...etc. How I have it right now, the data will be saved in the following order: Scan 1, Scan 2,...Scan1b, Scan2b, .... However I want to make a background immediately after each measurement so I want Scan 1, Scan 1b, Scan 2, Scan 2b..

I don´t want to go into more details because I think the simplified VI I sent summorizes the problem quite well.

Your suggestion looks interesting, would it be possible to extend the boolean you used while keeping the two loops instead of one? Also: can you send the actual VI? I can only see an image and I would need to recreated it by hand piece by piece on the block diagram.

 

Many thanks in advance, and let me know if anything is unclear!

 

0 Kudos
Message 4 of 10
(2,114 Views)

Sorry I forgot to add that I am using LabVIEW SP1 2014 version

0 Kudos
Message 5 of 10
(2,102 Views)

If you have 2 nested for loops that each use a 1D array, you can simply use Swap that Altenbach showed above to switch them. If it's a 2D array you can use a Transpose on the array.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 10
(2,083 Views)

Well, it is difficult to give more detailed advice without seeing the actual rest of the code. Here's the same in a stacked loop version.

 

altenbach_0-1651246687355.png

 

0 Kudos
Message 7 of 10
(2,070 Views)

Thank you for your feedback. I will try to be more precise with what I want. I have edited the subVI altenbach sent me for that purpose. The VI simply swaps the values of imax and jmax, but it doesn´t swap the order action of the loops. Notice in my VI, the order is always Experiment 1, Scan 1, Scan 2, ... Experiment 2, Scan 1, Scan 2, ...

 

instead of my wish: Experiment 1, Scan1, Experiment 2, Scan 1, ...Experiment1 , Scan 2, Experiment 2, Scan 2 ...

 

I input to my loops multidimensional arrays that determines what kind of experiment I want to do.

0 Kudos
Message 8 of 10
(2,055 Views)

Well, it seems like a really bad idea to bury all that inside a stack of loops. All you really need is a proper state machine and some logic that determines the sequence of tasks. One flat while loop!

Message 9 of 10
(2,038 Views)

Honestly you are right, I made a bad programming choice years ago and I have been builduing on it ever since. Now I am suffering the consequences!

0 Kudos
Message 10 of 10
(2,019 Views)