LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to array using for loop

Hello all,

 

I created a VI called "Get Data" (see below) that takes multiple string arrays and organizes the information into a 2D Array ("Window List"), a single row with 85 columns. (Side note: Each row represents data about a window) 

 

vi.JPG

 

I wired i+1 to my VI, so iteration 0 writes Window 1, iteration 1 writes window 2, etc etc. 

I wired the total # of windows/rows to write to "N", so the loop would stop after the last window has been written to the array.

 

Here is an example of one row of data (yes, the gaps are necessary, unfortunately)

windowlist.JPG

 

The problem I'm having is that it doesn't retain each row of data between iterations. Once the loop completes, I am left with only the last row of data that my VI wrote. How do I have the VI fill all rows instead of only the last one?

0 Kudos
Message 1 of 3
(2,340 Views)

This is kind of basic LabVIEW...you might want to look into a class or tutorial.

 

There are a few ways to do what you want to do.  The simplest one is to use a shift register and a "build array" function.  The input shift register and the output from your subVI will be wired to the "build array" function inputs.  The output of the "build array" function will be wired to the output shift register.

 

If you have your data come out of your subVI as a 1D array (1 row containing 85 elements), then you can right-click on the FOR loop border and select "enable indexing".  The result will be a 2D array, each row containing the data set from a single loop iteration.

 

Hope this helps a little.

0 Kudos
Message 2 of 3
(2,336 Views)

You should probably bundle all related wires so you can use less connectors.  (Unbundle them inside the "Get Data" sub-VI.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 3
(2,309 Views)