From: Robert Dinterman on
Hello-

I am running into some trouble while using textread or even textscan in reading my data. Here is a sample of my data:

>"USC00011084192604TMAX 222 6 244 6..."
>
>Columns 1-11: "ID"--> 'USC00011084'
>Columns 12-15: "YEAR"--> '1926'
>Columns 16-17: "MONTH"--> '04'
>Columns 18-21: "ELEMENT"--> 'TMAX'
>Columns 22-26: "VALUE1"--> ' 222' (notice two spaces before 2)
>Columns 27-27: "MFLAG1"--> ' ' (sometimes this takes on a value)
>Columns 28-28: "QFLAG1"--> ' ' (sometimes this takes on a value)
>Columns 29-29: "SFLAG1"--> '6'
>Columns 30-34: "VALUE2"--> ' 244' (two spaces before 2)
>Columns 35-35: "MFLAG2"--> ' '
>Columns 36-36: "QFLAG2"--> ' '
>Columns 37-37: "SFLAG2"--> '6'
>... and these continue until 31

The code I have been using is:

>>fmt='%11c %4c %2c %4c %5c%1c%1c%1c %5c%1c%1c%1c ...';
>>[ID,YEAR,MONTH,ELEMENT,VALUE1,MFLAG1,QFLAG1,SFLAG1,VALUE2,MFLAG2,QFLAG2,SFLAG2...] = textread('fid', fmt);

The first element of the outputs are as follows:
>ID--> 'USC00011084'
>YEAR--> '1926'
>MONTH--> '04'
>ELEMENT--> 'TMAX'
>VALUE1--> '222 ' (notice, two spaces after 2)
>MFLAG1--> '6'
>QFLAG1--> '2'
>SFLAG1--> '4'
>VALUE2--> '4 6 ' (notice, two spaces in between and one after 6)

So you can see that the problem I am encountering is when there are consecutive whitespaces. Does anyone have suggestions how I can tell Matlab that every space (regardless of what precedes or follows) should be counted as a character? Thanks in advance.
From: Walter Roberson on
Robert Dinterman wrote:

> I am running into some trouble while using textread or even textscan in
> reading my data. Here is a sample of my data:

> So you can see that the problem I am encountering is when there are
> consecutive whitespaces. Does anyone have suggestions how I can tell
> Matlab that every space (regardless of what precedes or follows) should
> be counted as a character?

Use textscan() and play around with setting Delimiter to '' or
Whitespace to '' (not both)
From: Robert Dinterman on
Walter Roberson <roberson(a)hushmail.com> wrote in message
> Use textscan() and play around with setting Delimiter to '' or
> Whitespace to '' (not both)

Setting Whitespace to '' did it. Thank you very much.