From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Save multiple arrays from nested loop

Solved!
Go to solution

Hello,

 

My vi generates multiple arrays in each loop iteration, and I would like to save the data. I've done some work with saving files before, but it was never with nested loops. I'm not sure how to keep the information from one loop iteration to the other. I'd appreciate any suggestions. I made this sample & simple vi (the attached file) that simulates the issue that I have. I'd like to have one file with a time column and various power columns next to it.

The first issue that I have is that I generate the time array only once, but a signal array multiple times, so how do I keep the time array from going to file multiple times? The other issue, as stated above, is saving the signal array data from being lost in the nested loops....

 

Thank you,

 

A

0 Kudos
Message 1 of 8
(3,598 Views)

You can put your array indicators outside the outermost For Loop with auto-indexing turned on at those tunnels, and now you'll have 2-D arrays.

 


@simply_me wrote:

  I'm not sure how to keep the information from one loop iteration to the other. I'd appreciate any suggestions.


Shift registers are a basic but important LabVIEW concept.  If you aren't familiar with them then I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

 

 


@simply_me wrote:

The first issue that I have is that I generate the time array only once, but a signal array multiple times, so how do I keep the time array from going to file multiple times?


 

Your VI doesn't show any file functions, so there is no way I can comment on that question.

 

 

0 Kudos
Message 2 of 8
(3,595 Views)

Hi Ravens Fan,

 

Thanks for your quick reply, I've modified my vi per your suggestion. Now, I get three arrays, but in reality I should get 9 signal arrays. Also, the over all combined array size (the final array outside) should be dynamic, i.e. adapt to the number of power cycles times wavelength cycles. If that makes sense. Your suggestion did solve my time array issue though :-).

0 Kudos
Message 3 of 8
(3,593 Views)

I don't know why you think you should have 9 arrays.  You only have 2 arrays, your time array and signal array.  Your signal array is dynamic as it is creating a 3-D array where each dimension represents 1.  # of data points you collected, 2.  the number of power cycles, 3. the number of wavelength cycles.

 

Do you actually mean you want a 2-D array where the number of elements in the second dimension is 9 (based on 3 x 3)?

 

If so, then you don't want to auto index the outer loop.  Use build array and a shift register so that you concatenate the inner 2-D array to itself.

 

0 Kudos
Message 4 of 8
(3,584 Views)

Sorry, I should have been more coherent, the middle loop generates 3 signal arrays each iteration and the outer loop runs 3 times, hence 9 one dim arrays, and an overall array of 3 by 3 in our case. So you were correct. I've modified my vi once again, and there is a couple of things-

1. The first signal term of the first array is always registered in the final array as 0 even though it's not (see attached jpg) regardless of its magnitude. I've tried to play around with precision and multiply everything by a factor of 10, but it is still 0.

2. The first column in the final array is the number of steps I assume, but I don't have a need for it. I guess I'll just omit it when I'll write to file.

 

I appreciate your help with this.

Download All
0 Kudos
Message 5 of 8
(3,577 Views)
Solution
Accepted by topic author simply_me

1.  The first signal element of the first array IS always zero.  The Simulate Signal always starts at zero.  You are comparing it to the "First Output" indicator.  That was gotten by converting the Dynamic Datatype to a scalar.  And that is always the last element of the actual data.  And since the "First Output" is overwritten on every iteration of the inner loop, the number you see in the end is actually from the very last iteration of data.  Look at "First Output" in comparison to the last element of your last array column and you'll see they are the same.

 

2.  The reason you have a first column that consists of steps is because that is what you have wired up to initialize the shift register.  If you look at my example, you'll see I have an empty array.  (The zero is greyed out.)  In yours, the 0 is not greyed out meaning there is an element.  Expand that array to show more elements, and widen the numeric field and you'll see more digits.  They match what is in your first column.

Message 6 of 8
(3,570 Views)

Thank you for clarifying it and for all your help.

0 Kudos
Message 7 of 8
(3,566 Views)

hi

 

to get a single array of time you can either create a for loop separately outside these nested loops or create a case structure in the outer for loop with condition (i=0) and execute the time only in this condition. do revert in case of clarification.

0 Kudos
Message 8 of 8
(3,559 Views)