Thread Subject: quick question about 'textscan'

Subject: quick question about 'textscan'

From: Apurva Dave

Date: 14 Sep, 2009 17:15:06

Message: 1 of 8

Hi,

I'm using textscan to read some tab-delimited data. I want to ignore the metadata as well as some comments. I'm using the following syntax, but I'm getting an 'unknown option' error when I try to use 'commentstyle':

fid = fopen('P980413A.DAT');

textfile = textscan(fid, '%f', 28, 'delimiter',' ', ...
'commentstyle', {'/begin_header /end_header@'}, ...
'commentstyle', '/begin_data', ...
'commentstyle', '/end_data@');

fclose(fid);

As far as I can tell, I've entered it all correctly. Parameters are not case-sensitive, although I also tried different versions just to check. Is this a bug in the matlab? I tried restarting.

'headerlines' isn't a good alternative for me, b/c the metadata for each data file aren't uniform. In any case I still need to find a way to ignore comments interspersed through the file. Any thoughts?

Thanks,
Apurva

Subject: quick question about 'textscan'

From: dpb

Date: 14 Sep, 2009 17:30:33

Message: 2 of 8

Apurva Dave wrote:
> Hi,
>
> I'm using textscan to read some tab-delimited data. I want to
> ignore the metadata as well as some comments. I'm using the following
> syntax,but I'm getting an 'unknown option' error when I try to use 'commentstyle':
>
> fid = fopen('P980413A.DAT');
>
> textfile = textscan(fid, '%f', 28, 'delimiter',' ', ...
> 'commentstyle', {'/begin_header /end_header@'}, ...
> 'commentstyle', '/begin_data', ...
> 'commentstyle', '/end_data@');
...

textscan() postdates my version and don't have time to look at web doc
right now, but does it indicate can have multiple 'commentstyle' entries
as allowable syntax? That's unusual at least w/ any ML function I'm
aware of....

--

Subject: quick question about 'textscan'

From: Apurva Dave

Date: 14 Sep, 2009 17:48:19

Message: 3 of 8

yup, that would be my problem. thank you!

does anyone have a suggestion for how to deal with metadata and comments by calling distinct paramaters (ie. without trying to call 'commentstyle' multiple times). once again, 'headerlines' isn't a good option for me b/c my metadata vary from file to file.

thanks,
apurva

Subject: quick question about 'textscan'

From: Rune Allnor

Date: 14 Sep, 2009 17:59:54

Message: 4 of 8

On 14 Sep, 19:48, "Apurva Dave" <|remove.this|apurva.dave|
remove.th...@duke.edu> wrote:
> yup, that would be my problem. thank you!
>
> does anyone have a suggestion for how to deal with metadata and comments by calling distinct paramaters (ie. without trying to call 'commentstyle' multiple times). once again, 'headerlines' isn't a good option for me b/c my metadata vary from file to file.

Don't use TEXTSCAN.

It seems your data might be complicated enough to warrant
you writing a dedicated parser.

Rune

Subject: quick question about 'textscan'

From: Apurva Dave

Date: 14 Sep, 2009 18:33:04

Message: 5 of 8

Thanks Rune, but that seems like something that's beyond my abilities right now...

Is there anyway I can make edits to my data files? E.g. within a loop, open each data file with read/write permissions, find and remove all metadata and comments? I know it's possible to fopen text files in read/write mode, but I don't know how to proceed from there...

I have ~200 data files, so opening them up in an editor and making changes myself is not an option...

apurva

Subject: quick question about 'textscan'

From: Rune Allnor

Date: 14 Sep, 2009 18:49:55

Message: 6 of 8

On 14 Sep, 20:33, "Apurva Dave" <|remove.this|apurva.dave|
remove.th...@duke.edu> wrote:

> Is there anyway I can make edits to my data files? E.g. within a loop, open each data file with read/write permissions, find and remove all metadata and comments?

Yes, there is: Write a parser.

Rune

Subject: quick question about 'textscan'

From: Apurva Dave

Date: 14 Sep, 2009 20:22:17

Message: 7 of 8

ok, will give it a shot. thanks!
apurva

Subject: quick question about 'textscan'

From: Andres

Date: 14 Sep, 2009 21:33:01

Message: 8 of 8

It looks like you (just) want to read numerical data with a variable number of header lines. It may be worth giving txt2mat from the mathworks file exchange a try.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
textscan fopen ... Apurva Dave 14 Sep, 2009 14:34:07
textscan comments Apurva Dave 14 Sep, 2009 13:49:06
textscan Apurva Dave 14 Sep, 2009 13:19:08
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com