LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do i read a text file data and display it on a graph

What I want to do is read in data from a text file (such as apple.txt) and display the data onto an xy graph. The data file is in 2 columns, representing a set of many x,y data points. Thefore the graph is to display this set of data points as a curve.

I would appreciate if someone could show me what I'm doing incorrectly, or if there is an easier way of accomplishing the same thing.

Thanks.
0 Kudos
Message 1 of 7
(5,930 Views)

You'll have to show us what you are doing now before we can tell what is incorrect about.Smiley Wink

 

You should look at the example for XY graph.VI and also Read from Text File.VI  A combination of those two should show you what you need.

 

If you still need help post your VI and also a copy of your text file.

Message 2 of 7
(5,923 Views)

Hai.

To read and display text file on a graph,u need to save the data in a text file using 2d array to string vi specifying Comma & Semi-colon as column and row seperators

Then use string to 2d array vi to display text on a Graph.Specify comma & semicolon as column & row seperators here also.

Check the attached vis for reference.

0 Kudos
Message 3 of 7
(5,911 Views)

Wow. OK, this is going to sound harsh, but sometimes, brashness is necessary... That's certainly a convoluted way of doing things. Why use a complicated way of saving 2D data when you have the Write to Spreadsheet File and Read From Spreadsheet File functions? Those 2 perform in a single step everything that you're trying to do with all of that code. The delimiter used to separate columns can be whatever you want, and I've never heard of using semicolons to separate rows. That's not to say you can't, but normally newline characters (specific to the operating system) are used.

 

Also:
  • Your front panel example uses Boolean buttons that are "Switch Until Released". These will not work properly unless the VI is running, and even then it's the wrong mechanical action since it will register a True while you are holding the button down, which means you could write/read the file more than once. This is pointless.
  • Your main VI has no loop, which means it relies on using the Run Continuously button in the toolbar. VIs should never be written this way.

 

While we appreciate you trying to help, please provide examples that work and that indicate a certain level of understanding of proper and efficient LabVIEW coding. I'm not trying to discourage you, but it is clear, at least to me, that this example is not one that the original poster should consider as a solution.

 

Message 4 of 7
(5,882 Views)

Well given the presenece of this thread I didn't see the point in starting up a new one given that wanting to display some text as described by the original poster is my initial aim here.  However, I think I have got the text to display, my problem is that is not presenting as it should.  Thus I have attached the vi I have come up with, the text file I want to read and graph and a image of how the data should be presented. 

 

The reason I am doing the vi like this is the moment is the next step will be to fit it using the non-linear fit vi using an equation I have.  Thus by graphing it initially here I can see I can do part of initially what I want to do.  Once I can do this I will then attempt to use the fitting vi and see how well the data fits to the known (ie model values).  (sorry if that last paragraph went slightly off topic.

 

I should note here that the reason I am using a text file with a sort of header is that the data that i will be getting from the DAQ card, and after it has been processed, will be of the form in the text file.  hence wanting to start fromt here.

 

thanks and any hep would be appreciated,

Download All
0 Kudos
Message 5 of 7
(5,737 Views)
You are not properly indexing the array. Your data is in columns, not rows. Also, the constant of 6 won't work in your case because your file contains extra tabs at the end of the lines for the first 10 lines. Even without these extra tabs the value of 6 does not take into account the CR/LF characters are the end of the line (which are an additional 2 characters). If those extra tabs are unavoidable, then you can simply ignore the start of read offset and use Array Subset to chop out the first row, and the use Index Array to get the first two columns which are your data. Then you can modify the graph as you want.
Message 6 of 7
(5,713 Views)

Thank you for that help.  I must apologies for the issue with the text file.  It is something I had noticed as well and I had deleted those extra tabs as well.  Obviously I sent ac opy of the file that i hadn't modified before I attached the file.  So the tabs aren avoidable, but maybe using the Array Subset is actually a good idea.  Ideally the data I will be working with will have more than one row (ie header information and stuff), so this might be a better way of dealing with the data.

 

Thanks for the help, I got it to work on my machien as well.  Much appreciated.
0 Kudos
Message 7 of 7
(5,684 Views)