From: Peter Riddersholm on
Hi,

I am having problems with importdata. My *.txt files are on the form:

Observed_precipitation_(mm) 1km daily 20050102 Rel20070101
1000286 442000 6157000 12.6 4 6096 6081 6080 6104
1000287 442000 6158000 12.6 4 6081 6058 6080
1000288 442000 6159000 12.6 4 6081 6058 6080 6104
1000289 442000 6160000 12.6 4 6081 6058 6080 6104
1000423 443000 6156000 12.6 5 6096 6081 6058 6080 6104
1000424 443000 6157000 12.6 5 6096 6058 6080 6081 6104
1000425 443000 6158000 12.6 5 6096 6058 6081 6080 6104
1000426 443000 6159000 12.6 5 6081 6096 6058 6080 6104
1000427 443000 6160000 12.6 5 6081 6096 6058 6080 6104
1000428 443000 6161000 12.5 5 6081 6096 6058 6080 6104

.... and so on

nheaderlines is perfect for dealing with the header. The problem arises as the number of elements in each row changes. I just want to be able to load data into a n-by-m matrix. I'd prefer if the blanks are filled out with NaNs.

I have also tried using textscan, but that doesn't work for me either :(

Can anyone help?
From: dpb on
Peter Riddersholm wrote:
....

> nheaderlines is perfect for dealing with the header. The problem arises
> as the number of elements in each row changes. I just want to be able to
> load data into a n-by-m matrix. I'd prefer if the blanks are filled out
> with NaNs.
>
> I have also tried using textscan, but that doesn't work for me either :(
>
> Can anyone help?

Are these tab-delimited or fixed width fields or what? The newsreader
wrap makes the file snippet posted indeterminate as to what the format
would be.

You'll have to have some way to discern what is missing as opposed to
what is simply a separator (that's what's not possible to tell from
posting).

In general, if is fixed width you can set up a format string to parse
it; if not you'll have to do something like read each line into a string
variable a la fgetl() and parse each line deciding on what/where the
missing values are/go...

--
From: Peter Riddersholm on
dpb <none(a)non.net> wrote in message <i0v87i$tfc$1(a)news.eternal-september.org>...
> Peter Riddersholm wrote:
> ...
>
> > nheaderlines is perfect for dealing with the header. The problem arises
> > as the number of elements in each row changes. I just want to be able to
> > load data into a n-by-m matrix. I'd prefer if the blanks are filled out
> > with NaNs.
> >
> > I have also tried using textscan, but that doesn't work for me either :(
> >
> > Can anyone help?
>
> Are these tab-delimited or fixed width fields or what? The newsreader
> wrap makes the file snippet posted indeterminate as to what the format
> would be.
>
> You'll have to have some way to discern what is missing as opposed to
> what is simply a separator (that's what's not possible to tell from
> posting).
>
> In general, if is fixed width you can set up a format string to parse
> it; if not you'll have to do something like read each line into a string
> variable a la fgetl() and parse each line deciding on what/where the
> missing values are/go...
>
> --

It is fixed width every line.

What would a format string look like? And then I'll have to use textscan, right?
From: dpb on
Peter Riddersholm wrote:
> dpb <none(a)non.net> wrote in message
> <i0v87i$tfc$1(a)news.eternal-september.org>...
....

>> In general, if is fixed width you can set up a format string to parse
>> it; if not you'll have to do something like read each line into a
>> string variable a la fgetl() and parse each line deciding on
>> what/where the missing values are/go...
>>
....

> It is fixed width every line.
>
> What would a format string look like? And then I'll have to use
> textscan, right?

That would depend on what the field width/description is.

Something like '%8n %6n %5.2f...' (just made up; I can't read the
listing well enough to try to fool with)

textscan, fscanf, perhaps textread even, yes...

--
From: Peter Riddersholm on
dpb <none(a)non.net> wrote in message <i0vaec$6jl$1(a)news.eternal-september.org>...
> Peter Riddersholm wrote:
> > dpb <none(a)non.net> wrote in message
> > <i0v87i$tfc$1(a)news.eternal-september.org>...
> ...
>
> >> In general, if is fixed width you can set up a format string to parse
> >> it; if not you'll have to do something like read each line into a
> >> string variable a la fgetl() and parse each line deciding on
> >> what/where the missing values are/go...
> >>
> ...
>
> > It is fixed width every line.
> >
> > What would a format string look like? And then I'll have to use
> > textscan, right?
>
> That would depend on what the field width/description is.
>
> Something like '%8n %6n %5.2f...' (just made up; I can't read the
> listing well enough to try to fool with)
>
> textscan, fscanf, perhaps textread even, yes...
>
> --

Thanks a lot.

And what about the header, then?

The files are 47615 rows long...