LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Multiple Columns From .txt and Do Statistics

Solved!
Go to solution

Hi,

 

I'm trying to write a vi that reads a file, calculates mean, std, and etc per column and then saves it to a new file.

I get an error at "Scan From String Function" which I can't find a way to resolve.

Also, after constructing the array, is it possible to find the mean, for example, of each column with out breaking down the array?

I've attached my vi so far and a sample txt file.

 

Thank you,

 

Download All
0 Kudos
Message 1 of 9
(5,423 Views)

You have several issues:

  • You are initializing a 2D array of integers, but your data is floating point.
  • Your string consists of several numbers separated by tabs. For this you should be using the Spreadsheet String to Array to convert the row you read into an array of numbers.
  • You are getting the error if you try to read past the end of the file. The Read from Text File function will generate an error, and the loops will keep going (but subsequent reads will be bypassed. However, you probably have the "Enable automatic error handling" options turned on in the LabVIEW options. This means that because you don't have the error clusters wired for the Scan From String function, LabVIEW will stop the execution when the Scan From String function generates an error, which it will when you tell it to parse an empty string.

 

Aside: Wouldn't it be easier to simply use the Read From Spreadsheet File VI?

0 Kudos
Message 2 of 9
(5,410 Views)

Thank you for your reply smercurio_fc.

ok, lets assume the input file is a spreadsheet not txt, I'm still not sure how to do operations by columns (like mean of a column).

How will it be different?

0 Kudos
Message 3 of 9
(5,400 Views)

A text file with delimiters is a spreadsheet file.

 

Look at the help for Read From Spreadsheet. The 'All Rows' output is a 2D array. Just index each column (Index Array function with the column input wired).

0 Kudos
Message 4 of 9
(5,392 Views)

The Read from Spreadsheet File reads text files, not Excel workbooks. This VI has been badly named from the start, and it confuses new people all the time. We've lobbied NI to change the name, but it has fallen on deaf ears. The VI will simply read in your file as a 2D array directly. You can then index out whatever columns you want to average, or if you want to do it for each column you can transpose the array and simply autoindex:

0 Kudos
Message 5 of 9
(5,390 Views)

Thanks again for your comments.

I always thought that spreadsheet means excel, so I didn't even bother checking it out. It is a confusing name indeed. 

I've tried both suggested vi's, but the second vi (with the for loop) didn't work because of different dimensions I believe.

So I've using this vi (see attached file), how can extract the next row?

Since I have 5-6 rows, I would hate repeating the same process for each one, isn't there a way to create an array with the mean of each column (as one entry)?

0 Kudos
Message 6 of 9
(5,375 Views)

Don't use the First Row (1D) output. Use the 2D (as mentioned) which is the entire file.

 

Please turn on Context Help. You will save a lot of time if you read the information in that window.

0 Kudos
Message 7 of 9
(5,367 Views)

The thing is that the 2D method doesnt work, when I try to construct the suggested vi.

Please see attached file.

0 Kudos
Message 8 of 9
(5,349 Views)
Solution
Accepted by topic author simply_me

You are not listening (or in this case reading). Use the 2D array output (called "all rows), NOT the 1D array output.

Message 9 of 9
(5,345 Views)