04-28-2022 03:56 PM
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!
04-28-2022 05:01 PM
(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?
04-28-2022 05:15 PM
04-29-2022 03:20 AM
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!
04-29-2022 06:31 AM
Sorry I forgot to add that I am using LabVIEW SP1 2014 version
04-29-2022 09:56 AM
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.
04-29-2022 10:39 AM
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.
04-29-2022 02:00 PM
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.
04-29-2022 06:19 PM
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!
04-30-2022 01:46 PM
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!