09-12-2025 05:16 PM - edited 09-12-2025 05:17 PM
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?
09-12-2025 06:02 PM - edited 09-12-2025 06:04 PM
09-13-2025 10:20 AM
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
09-15-2025 05:41 PM
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,
09-15-2025 05:44 PM
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,
09-17-2025 11:01 PM
@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.
09-17-2025 11:03 PM
@AnkitG wrote:
Can you provide a visual diagram for it?
All diagrams are "visual".