LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read text file

Hello,

 

I am trying to read a text file containing string and numbers...Then I would like to perform some statistic calclulation of numbers....

The text file is some thing like this:

 

Date                          Time                 Status            Speed(rpm)          Time (ms)

20122014                1515                 OK                 1250                       250

20122014                1516                 NOK              1261                        -

 

I succesfully read the text file using "Read from Text file Function". 

However, in the third line, since the value of time is "-", my fucntion read it az Zero !! Do you know why?

This cause an error in my statistic calculation.

Do you know how can I get rid of this "-" in my reading?

 

Thanks alot,

 

0 Kudos
Message 1 of 5
(2,811 Views)

You will need to handle this case yourself and think about what you want to happen with those data points. I think doing a string replace before the spreadsheet string to array function might work. If you replaced the "-" with "NaN", LabVIEW will use the DBL Not A Number instead of 0. I'm not sure if the statistical functions will ignore NaN's in their calculations though but at least you could filter out the NaN's before doing the calculations instead of potentially having 0's from dashes and actual 0's as data points.

 

The reason it does this is because 0 is the default data type for a DBL and it's not possible to convert a "-" to a number so it uses the default value.

 

This should work:

2015-01-06_09-37-41.png


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 5
(2,801 Views)

Be careful about just arbitrarily replacing "-" with "NaN" in the initial string.  You could be messing up some legitamite negative numbers.  You might just want to use the Spreadsheet String To Array to convert into a string array and then replacing before converting into a number.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 5
(2,782 Views)
Maybe you want to remove the NOK lines from the data?
0 Kudos
Message 4 of 5
(2,756 Views)

Thank you very much.

I used your method and it worked.

 

Many thanks and bests regards.

 

0 Kudos
Message 5 of 5
(2,737 Views)