LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initializing an empty 2D array for shift register?

Howdy all!

 

I'm in need of some help regarding the best practice to initialize a new empty 2D array for a shift register inside a while loop.

 

I'm trying to record data from 2 inputs (I've replaced these with RNGs for the sake of simplicity) along with an elapsed time. The data is then recorded and saved to csv after a button is pressed to begin a new trial. The problem I'm running into is that if I don't empty out the array, I just end up recording all the previous trials (obviously this would defeat the whole purpose of dynamically naming the csv files if the last one will just contain all of the data from all the trials). What are some good ways of solving this?

 

Thanks in advance folks!

Download All
0 Kudos
Message 1 of 6
(2,541 Views)

Wire the array across the case structure and output an empty array when a new trial starts.

0 Kudos
Message 2 of 6
(2,534 Views)

Some more generic comments to your coding style:

 

  • Please don't maximize the diagram to the screen. Most of us multitask and e.g. write a forum reply while looking at the diagram. Fullscreen prevents this and it is annoying to stare at huge areas of whitespace.
  • Your sequence structure is not needed, because the order or execution is irrelevant for the +1 here. The wire already enforces the correct execution order.
  • A state machine would probably a better architecture. 
  • You should divide by a value derived from the wait, and not a 100 diagram constant. Now if you would change the wait later, you need to remember to make related changes elsewhere.
  • You can add all strings to the format code to generate the file name. No need for all that string gymnastics. (Format would be "Trial%03.0f.csv")

 

saveem.png

Message 3 of 6
(2,525 Views)

Hi Altenbach,

 

Thank you for your help, particularly with the format string trick which has made my life much easier, esp. since I'm new to labview

 

One last question: Is there a method to get headers into the csv?

 

Thanks in advance!

0 Kudos
Message 4 of 6
(2,497 Views)

Yes, of course. Write a 1D arrays of header strings first, then append your data.

0 Kudos
Message 5 of 6
(2,485 Views)

@altenbach wrote:
  •  
  • You can add all strings to the format code to generate the file name. No need for all that string gymnastics. (Format would be "Trial%03.0f.csv")

Since its an integer, more correct would be "Trial%03d.csv", of course. The result would be the same.

0 Kudos
Message 6 of 6
(2,454 Views)