LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save elapsed time with 2D data to a text file

Hi All,

 

I have 2D data that I save into a text file in 4 columns. I am trying to save the elapsed time as the first column, but my program is saving it as a row instead of a column.

Can anyone suggest what I am doing wrong here? I wonder if I need to change the time data to a vector or something?

AnkitG_0-1757715311391.png

 

0 Kudos
Message 1 of 7
(190 Views)
  • How does the array look like coming out of the IO?
  • If you have more than one row with the same time data, you need to create an array of sufficient size.
  • Do all array operations in orange and write that to file. a format of %.8f is silly if you write strings formatted as integers.
  • Maybe prepend the time before transposing?
  • There is always "insert into array"
  • Can you reduce the example to a simulation, creating typical data. We don't have your hardware.
  • Please don't maximize the front panel and diagram to the screen.
  • Never (never ever!) have controls or indicators with an empty string as label. You can hide the label in the front panel if you don't want to see it, but it should always show on the diagram.
0 Kudos
Message 2 of 7
(166 Views)

I cannot see your code (only the small section shown in the picture of some code), but it looks like you are using Write Delimited Spreadsheet to save your data.  It also appears (though I can't see it on the picture) that you are writing multiple channels and multiple samples -- I'm going to assume that if you had 4 channels and took 100 samples at a time, this would appear as "100 rows with 4 columns", which makes appending the next batch of 100 samples very easy.

 

If this is true, "pre-pending" an initial column that is Elapsed Time (what accuracy do you need?  Is "milliseconds since the previous write, with the first write being 0 ms" adequate?  If that's the case, the simplest way to do this requires a Shift Register and Tick Count (ms), which returns a U32 that "counts milliseconds".  Initialize the Shift Register with Tick Counts just before you want to get elapsed time.  Now, inside your acquisition Loop, Elapsed Time = Tick Count (that you read "inside the loop" - Tick Count (from Shift Register), and you update the Shift Register (from inside the loop) with the just-read Tick Count.  Note that the result will be a U32, which you can change to a Dbl so all the columns of your Data File are Dbls.  Note that if you do collect multiple samples with DAQmx, the time will be the time that the last sample was collected, not the first one.

 

Bob Schor

0 Kudos
Message 3 of 7
(124 Views)

Hi,

 

Thank you so much for your suggestion and reply.

 

Yes, it's a 2D array (orange) coming from 4 channels. I am saving the data in a text file, and each iteration of a while loop saves a row with 4 columns. I am trying to add an additional column for the elapsed time between those iterations. I tried insert to array, but it ended up creating a new row with 1 column containing the elapsed time, and the other two rows with just 0's

 

Thanks,

0 Kudos
Message 4 of 7
(86 Views)

Hi,

 

Thank you,  yes, I need milliseconds accuracy. I am trying to add a column of elapsed time between iterations. I will try the shift register technique.  Can you provide a visual diagram for it? 

 

Thank you so much for the help

 

Thanks,

0 Kudos
Message 5 of 7
(84 Views)

@AnkitG wrote:

Yes, it's a 2D array (orange) coming from 4 channels. I am saving the data in a text file, and each iteration of a while loop saves a row with 4 columns. I am trying to add an additional column for the elapsed time between those iterations. 


If you only get one row per iteration, why is it a 2D array?? It should be a 1D array with four elements. Now just prepend the time  (using "built array") and write that 1D array with five elements to the file.

 

0 Kudos
Message 6 of 7
(30 Views)

@AnkitG wrote:

Can you provide a visual diagram for it? 


All diagrams are "visual".

0 Kudos
Message 7 of 7
(28 Views)