LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save X and Y values using waveform chart?

Hi,

I have a very basic doubt. I want to save the values of a waveform chart (both X and Y axis) in text file. Is there any way to save the data with time (in arbitrary unit)? 

Also, 'write to spreadsheet' saves data of the format %3f i.e., upto 3rd place of decimal only. I want to save the numbers as the actually are (upto whatever place of decimal).

Can somebody please help?

I am attaching a VI based on the way I am trying to save the data.

0 Kudos
Message 1 of 21
(3,369 Views)

You can right click on a graph when it has data in and open the 'Export' menu and select export to clipboard or excel.

 

The formatting does leave something to be desired if you do this.

 

Niatross_0-1582454810568.png

 

Write to delimited spreadsheet is better, using the format string %#_g should result in what you want.

 

Personally I prefer using the 'Array to spreadsheet string' function and then write to file.

 

Niatross_3-1582455133728.png

 

0 Kudos
Message 2 of 21
(3,341 Views)

Actually I am having 2009 version of LabView, so this export option is not available there.

0 Kudos
Message 3 of 21
(3,335 Views)

There is a format specifier input on the top of that node.

 

Wire a constant string to it with a longer format specifier, e.g. "%.9f" or whatever.

formatspecifier.png

 

Note that the VI was deprecated in later versions of LabVIEW, hence the big red "X" through the icon.


GCentral
0 Kudos
Message 4 of 21
(3,325 Views)
  • Thank you for the replies. But I am still not getting how to save the data of X axis as well. I want to save the data of both X and Y values. Since X is time, it can be in arbitrary unit.
  • One more thing I want to ask. In the shown example, there is only a random number generator inside the while loop, hence it was easy to put the condition for it separately. But for my experiment, I am using a much bigger code. There is already several function inside the while loop. How should save the data of the random number generator in such case then? 

Please suggest some way for saving a number in the waveform chart which is changing after each iteration (saving time values also).

 

0 Kudos
Message 5 of 21
(3,316 Views)

So you don't want to save a large block of data, you want to save each individual datapoint as it is written to the chart.  Am I correct?

 

Then open the file before you start, and use Write to Text File functions to save your data point.

 

To come up with the X (time) value, you need to realize a chart's X value is based on the T0 (initial time) and the dT (time between points).  So if saving a large block of data from a chart, you'd need to create all your X values based on T0 and dT.  You can do that in a loop.

 

Since you want to save the data a point at a time as it is written to the chart, just combine your current timestamp with the Y value you are sending to the chart and write that to the file.

0 Kudos
Message 6 of 21
(3,309 Views)

What do you want to be in your x axis? Whatever it is you need to create an array where column 0 is your x axis data and column 1 is your y axis data (Row 0 and Row 1 if you don't have the Transpose input of write to spreadsheet set to True). You then wire this into the 2D array of Write to Spreadsheet.

 

The x axis could just be iteration (In which case you can use the i terminal of your while loop) or it could be time elapsed/current time

 

Also, an observation, you are currently prepending each new value to the beginning of the array, this will result in the newest data been shown at the top of your file. Normally it would be the other way around, newest data at the bottom of your file. THat is up to you though

 

I am not entirely sure I understand your second question. It might be worth posting an example of your larger code.

 

0 Kudos
Message 7 of 21
(3,307 Views)

Looks like I could not explain my problem properly. Here is the whole thing step by step:

  • I am having a waveform chart which is inside a while loop. And the input of waveform chart is not an array but a number. So basically I seeing a number which is changing after each iteration(as it is in a while loop) in the waveform chart. This variation of the number can be seen like a waveform though (due to running of the loop).
  • I want to save the data of this waveform chart into text file (both X and Y axes).
  • Now since on Y axis, there is no array, I can not save it directly to the speadsheet.
  • So, I am trying to build an array with the numbers (i.e. Y axis values).
  • But, I a not getting how to do this. Because the whole code is already in a while loop and loop condition is already set according to other requirements.
  • Now how should I save the data in a text file which involve both X and Y axes of the waveform chart (X is not even an array)?

Thank you in advance.

0 Kudos
Message 8 of 21
(3,300 Views)
  • Construct X according to your preferred rules - either add "dt" each iteration (if constantly spaced in time) or use Get Date/Time in Seconds, or record your "timestamp" value by some other means. A Shift Register might be useful here (when adding dt)
  • Probably if using Get Date/Time in Seconds you'll want to find the initial time first and subtract the new time from that value (for relative time). For absolute time, don't do this.
  • Branch the "Y" value wire going to your Chart.
  • Now you have a pair of values for X and Y (either as two doubles, or a timestamp and a double)
  • Use Format to String or Array to Spreadsheet String to create a string with appropriate formatting - e.g. a comma separating the values, suitable number of decimal places etc
  • Use Write to Text File in the loop to store the data
  • For greater efficiency (if your loop rate is fast) consider a Producer/Consumer design, and in this case, enqueue the values (a cluster of X, Y perhaps) and dequeue, then format, then store in a text file in the Consumer.

GCentral
0 Kudos
Message 9 of 21
(3,298 Views)

Thank you for this detailed suggestion. So here is the concerned part of the code.

 

 

Capture.PNG

 I am using the min value of a min max array as Y for waveform chart. But the build array function is taking the valu at 0th index only. So at the end, I am getting just one value (obtained from the last iteration).

Even if I ignore X values here, atleast Y values I need in a column.

 

Thank you

0 Kudos
Message 10 of 21
(3,288 Views)