LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read multiple file

Hello everyone, I need help reading multiple files in labview. I want to read the data from multiple txt files to form a graph. Then I want to save the results for Conductivity and slope into a new txt file to make a new graph. Is it possible?

0 Kudos
Message 1 of 2
(818 Views)

Forgive me if this observation seems harsh (it could actually be a kind of compliment), but it looks as though you are "teaching yourself LabVIEW", with no instructor, text, nor video to guide you.  Not too shabby, but there are a whole lot of "curiosities" in your code (like "What was he, or she, thinking?").

 

Rather than go that route, I'm going to put on my "Professor" hat and try to help you "think through" this problem.

 

  1. First, you have a number of text files consisting of three rows of "text" that you plan to discard, and some number (possibly always 10, I haven't checked) of 2-column tab-separated numeric data.  The first column is Voltage, the second is Current, and the numbers are considered as Floats.
  2. You don't want to do anything with the first three lines, but only deal with the numeric data, conveniently organized in 2 columns (and a potentially unknown number of rows).
  3. You want to measure "conductivity" from these set of Voltage/Current numbers.  Question -- is 0, 0 really an "experiemental" point where conductivity is defined?  [Think mathematics, the formula for conductivity, and how you handle a pair of zeros].
  4. You want to plot the data on a Graph, along with calculating the slope of a straight line best fitting the measured points (is it legitimate to have [0, 0] be a "measured" point?).

Let's start with File I/O, especially Text File I/O.  There are two very nice functions for reading Text Files -- Read Text Files (which you use) and Read Delimited Spreadsheet (which, if it weren't for those darn header rows, your file certainly is.  So let's fix this.  What would you have to do to take your file of 13 lines, all text files, and get a text array of everything except the header?  Read the Detailed Help for "Read from Text File", paying particular attention to "Count".  [Help yourself by typing Ctrl-H, which turns on "Auto-Help" -- hover your mouse over a LabVIEW Function on the Block Diagram and Help pops up, allowing you to click on Detailed Help].  So you should be able to modify your File I/O code to get a String consisting of only the numeric data (with or without the 0, 0 entry, you decide ...].

 

Remember I mentioned "Read Delimited Spreadsheet"?  This is difficult to use here because it doesn't allow you to skip header lines, only header characters, which is why I suggested doing Read Text Files, but specifying at least the number of Header lines you want to skip.  But now look at the String Palette -- see anything with a familiar-sounding name?  Fortunately for you, two of its four parameters have defaults that match yours (namely Tab-delimited, and array type, 2D Array of Dbl], so you only need to specify format (%f) and your String.

 

Here's a trick it took a BME student to tell me after I'd been doing LabVIEW for several months -- when you use Index Array (to get out, say, a row or column of an array) and you want to get out, say, multiple Rows or Columns, you can simply "drag down" on the bottom of the function, wire nothing into the "Index" (the black square), and the indices will automatically become 0, 1, 2, ...  This "feature" works for both Rows and Columns of a 2D Array, but if you want to auto-index columns, you need to wire the 0 to the Column (the second) indicator and you'll select all the Columns.

 

So no more Delete from Arrays needed!

 

You use an In-place Element Structure where none is needed.  Don't do this, you aren't ready for this feature yet.  What are you trying to do here?  Think about it -- you have an Array of Voltages (0 .. 9), and Array of Currents (0 .. some_number), and you want to express "conductivity" via some formula (which involves division).  Oops, are you trying to evaluate 0/0?  Didn't anyone ever tell you not to do that?

 

So say you get an array of meaningful Conductivity numbers from the non-zero values.  What do you want to do with this array of quotients?  Certainly not compute the size of the array, right?  Maybe compute a Mean?  [Right-click to bring up the Palettes, notice one called "Mathematics" ...]

 

Another mis-used In-Place Element Structure holds your Mean Square Method.  Hmm, though this is a novel (to me, anyway) of "mis-using" this Structure, maybe you've discovered a clever way of isolating and labeling a section of code so you can understand what you were doing when you come back to it!  Forgive my earlier negative remarks on this unusual practice.  But while you're at it, go back to the Mathematics sub-Palette and see if any of the other topics looks appropriate for "Mean Square Method" (no sense re-inventing the wheel).

 

Clean up your code, and come back if you still want further help (like how to automate "walking through" all the files).

 

Bob Schor

 

 

Message 2 of 2
(795 Views)