Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
load text-data from file

Subject: load text-data from file

From: erik hellström

Date: 1 Mar, 2013 10:27:07

Message: 1 of 3

hi
i have very large ascii files with data that i need to read. Sometimes text can be at the place where usually numbers are (errors, alarmText etc) Se below for an illustrative example:

Mass:Some:Hey
1:34:32
2:error:221
3:43:343
4:32:12

I try importdata with : as delimiter, this understands the header-row and reads the first line correctly but messes up the second (says both pos 2 and 3 is NaN) and stops reading (both row 3 and 4 is skipped altogether). Could i get this to work?

The other thing i tried is using textScan and if i specify each position as reading a string (%s) and that works. But then i need to convert 100 000s of strings to numbers which is very slow. If i read a column as number (%f) it stops reading the moment it reaches a text. Is there a way to make it enter NaN at that position and continue reading?

Thanks for your help
Erik

Subject: load text-data from file

From: dpb

Date: 1 Mar, 2013 14:06:30

Message: 2 of 3

On 3/1/2013 4:27 AM, erik hellström wrote:
...
> i have very large ascii files with ...
> text ... at the place where usually numbers are (errors, alarmText
> etc) Se below for an illustrative example:
>
> Mass:Some:Hey
> 1:34:32
> 2:error:221
> 3:43:343
> 4:32:12
>
> I try importdata with : as delimiter, this understands the header-row
> and reads the first line correctly but messes up the second (says both
> pos 2 and 3 is NaN) and stops reading (both row 3 and 4 is skipped
> altogether). Could i get this to work?
...

Best chance is probably the 'treatAsEmpty', option that will not return
NaN but empty cells (presuming it works correctly; there are at least a
few cases where there are interactions w/ other options that negate it's
effect)

  'treatAsEmpty', {'error', 'alarmtext', '...etc...'}

The problem is you have to have a comprehensive list of all the possible
matching strings so if the alarmtext above is a placeholder for some
long list of possible errors you're probably out of luck for this option.

Failing that, irregular file formats are a pain in the proverbial
appendage--you'll have to parse it one way or another accounting for the
irregularity.

--

Subject: load text-data from file

From: Cory

Date: 1 Mar, 2013 23:27:07

Message: 3 of 3

No promises, but there are some user-created files that attempt to get at this problem (e.g. csvimport).

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us