LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from spreadsheet and plot multiple XY graph

Solved!
Go to solution

Insert a point containing NaN whenever the current x value is smaller than the previous.

Actually, it looks like you are just reading an extra empty line. So either fix the file or discard rows that are all zero.

Message 11 of 14
(1,812 Views)

Trevillyan,

 

     It is considered "bad form" to add your own question to someone else's original post -- it is better to start a New Message with an original title (it helps you, the people who might want to help you, and the people who might want to get help with your very question).

 

     I noticed that your text file had blank lines at the beginning and end of the file.  This can really mess up Read from Spreadsheet (or Read Delimited Spreadsheet).  Is the attached picture what the graph should look like?

Spreadsheet Plot.png

Rather than attach the Block Diagram that produced this graph, I'm going to walk you through the logic, as there are some useful ideas that you might learn.

 

First, Know Your Data.  By this, I mean know that you have blank lines at the beginning and end, which means that you need to think about doing Reads that will allow you to deal with those blank lines.

 

One way to do this is to not use the "Read from Spreadsheet" function, but the simple Read Text File.  This requires that you first Open the file, then start reading.  You already know that your file is supposed to be a Text File that contains three numbers (which we will consider to be Floats), and that your file is organized in Lines by means of some line-separator character(s) (in your case, it is <CR><LF>).

 

A good way to read line-based Text files is with Read from Text File with both the Read Lines and Convert EOL options turned on.  If you leave the Count input unwired, this defaults to reading one line from the Text file, generating an Error when there are no more lines to read.  "Aha!", you should be thinking, "This suggests that I put the Read into a While Loop and wire the Error Line to the Stop Indicator so it will stop when it tries to read past the End of File".

 

OK, that gets the file read, a line at a time, ending when we try to read past the End of File.  I'm sure you realize that the first thing we need to do after exiting the While loop is to clear the Error Line, right?

 

Now, still within the While loop, we have a line of characters (or maybe nothing if we read past EOF).  What do we want to do with this line of characters?  Why, parse them into three numbers.  That is precisely what "Scan from String" is designed to do.  Wire the String as input, and notice that (by default) you get a Float output.  Drag down the bottom edge and you'll get three Floats.  Each represents the output of a column, which you can wire into an Indexing Terminal on the output of the While Loop.

 

I hope you have been paying attention here and ask the obvious question, "But what if the line is blank?".  If you look at the Help for Scan from String (or, better, if you try this yourself), you'll see that trying to scan from a string that doesn't meet the default line format (which here is 3 floats) -- you guessed it -- generates an Error.  "Not another error, what am I going to do with that?"  Do you know about Condition Tunnels?  If you right-click the three Indexing Tunnels, you'll notice they have a Conditional option -- a Boolean input that determines if the value is added to the array or not.  Well, if there's an error after Scan from String, you do not want to add this.  How do you change an Error in to "Not an Error"?  How about the Boolean "Not" function?

 

OK, so now when you exit the While Loop, you should have (a) the Error Line set because of hitting End of File, and (b) three Arrays filled with the three columns of data from the non-blank rows.  We already talked about getting rid of the Error Line, and we should also remember to close the File Reference we used to read the data (incidentally, that File Reference needs to be on a Shift Register within the While loop -- for Extra Credit, think about whether or not the Error line should be on a Shift Register).

 

We now have three arrays, X, Y1, and Y2.  It is extremely easy to combine these properly and wire them to the XY Graph to produce the above diagram (just look at the Help for the XY Graph).  Have at it!

 

Bob Schor

0 Kudos
Message 12 of 14
(1,789 Views)

the same problm i have..pls help me out...

Message 13 of 14
(1,500 Views)

Hi dheen,

 

the solution is shown above: when you have the SAME problem you should use this solution!

 

(And please don't create double posts!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 14 of 14
(1,490 Views)