textread error: Trouble reading floating point number from file

  • Follow


I am trying to read in a csv file (see below for example), but I keep getting this error message:
??? Error using ==> dataread
Trouble reading floating point number from file (row 2, field 5) ==> Left-Inf-Lat-Vent

Here is my script:
[a,b,c,d,e,f,g,h,i,j]=textread('/home/corinna/blstats/subject1.pet.segstats.csv','%*s%2d%4f%5f%5f%32q%f%f%f%f%f',...
    95,'headerlines',52);

The first part of the .csv file looks like this:
1   4      6258     6258.0  Left-Lateral-Ventricle         11979.8975  2929.6318  8061.0000 26612.0000 18551.0000 
  2   5       630      630.0  Left-Inf-Lat-Vent              14453.3525  1466.4132 11027.0000 18501.0000  7474.0000 
  3   7     12983    12983.0  Left-Cerebellum-White-Matter   17339.1094  2888.9805  6831.0000 24044.0000 17213.0000 
  4   8     43987    43987.0  Left-Cerebellum-Cortex         18461.0918  3642.9954  2595.0000 26536.0000 23941.0000 
  5  10      5804     5804.0  Left-Thalamus-Proper           20808.2539  3354.9368 12496.0000 29235.0000 16739.0000 
  
0
Reply corinna 9/7/2010 10:38:04 PM

On 10-09-07 05:38 PM, corinna bauer wrote:
> I am trying to read in a csv file (see below for example), but I keep
> getting this error message:
> ??? Error using ==> dataread
> Trouble reading floating point number from file (row 2, field 5) ==>
> Left-Inf-Lat-Vent
>
> Here is my script:
> [a,b,c,d,e,f,g,h,i,j]=textread('/home/corinna/blstats/subject1.pet.segstats.csv','%*s%2d%4f%5f%5f%32q%f%f%f%f%f',...
>
> 95,'headerlines',52);
>
> The first part of the .csv file looks like this:
> 1 4 6258 6258.0 Left-Lateral-Ventricle 11979.8975 2929.6318 8061.0000
> 26612.0000 18551.0000
 > 2 5 630 630.0 Left-Inf-Lat-Vent 14453.3525
> 1466.4132 11027.0000 18501.0000 7474.0000

What were you expecting? Your 5th field specifier in the format is %5f which 
is a format for a floating point number, but your fifth field is
'Left-Lateral-Ventricle' which is definitely not a floating point number.

Were you expecting the initial %*s to somehow read from the beginning of the 
line to the end of the 'Left-Lateral-Ventricle' string?
0
Reply Walter 9/7/2010 10:43:54 PM


Walter Roberson <roberson@hushmail.com> wrote in message <i66fai$bip$1@canopus.cc.umanitoba.ca>...
> On 10-09-07 05:38 PM, corinna bauer wrote:
> > I am trying to read in a csv file (see below for example), but I keep
> > getting this error message:
> > ??? Error using ==> dataread
> > Trouble reading floating point number from file (row 2, field 5) ==>
> > Left-Inf-Lat-Vent
> >
> > Here is my script:
> > [a,b,c,d,e,f,g,h,i,j]=textread('/home/corinna/blstats/subject1.pet.segstats.csv','%*s%2d%4f%5f%5f%32q%f%f%f%f%f',...
> >
> > 95,'headerlines',52);
> >
> > The first part of the .csv file looks like this:
> > 1 4 6258 6258.0 Left-Lateral-Ventricle 11979.8975 2929.6318 8061.0000
> > 26612.0000 18551.0000
>  > 2 5 630 630.0 Left-Inf-Lat-Vent 14453.3525
> > 1466.4132 11027.0000 18501.0000 7474.0000
> 
> What were you expecting? Your 5th field specifier in the format is %5f which 
> is a format for a floating point number, but your fifth field is
> 'Left-Lateral-Ventricle' which is definitely not a floating point number.
> 
> Were you expecting the initial %*s to somehow read from the beginning of the 
> line to the end of the 'Left-Lateral-Ventricle' string?

I was expecting the initial %*s to skip the space at the beginning of each line. If I remove the %*s then the error changes to the 6th field, rather than the 5th. I'm new to matlab and not really sure which formats to use.
0
Reply corinna 9/7/2010 10:59:05 PM

Walter Roberson <roberson@hushmail.com> wrote in message <i66fai$bip$1@canopus.cc.umanitoba.ca>...
> On 10-09-07 05:38 PM, corinna bauer wrote:
> > I am trying to read in a csv file (see below for example), but I keep
> > getting this error message:
> > ??? Error using ==> dataread
> > Trouble reading floating point number from file (row 2, field 5) ==>
> > Left-Inf-Lat-Vent
> >
> > Here is my script:
> > [a,b,c,d,e,f,g,h,i,j]=textread('/home/corinna/blstats/subject1.pet.segstats.csv','%*s%2d%4f%5f%5f%32q%f%f%f%f%f',...
> >
> > 95,'headerlines',52);
> >
> > The first part of the .csv file looks like this:
> > 1 4 6258 6258.0 Left-Lateral-Ventricle 11979.8975 2929.6318 8061.0000
> > 26612.0000 18551.0000
>  > 2 5 630 630.0 Left-Inf-Lat-Vent 14453.3525
> > 1466.4132 11027.0000 18501.0000 7474.0000
> 
> What were you expecting? Your 5th field specifier in the format is %5f which 
> is a format for a floating point number, but your fifth field is
> 'Left-Lateral-Ventricle' which is definitely not a floating point number.
> 
> Were you expecting the initial %*s to somehow read from the beginning of the 
> line to the end of the 'Left-Lateral-Ventricle' string?

I was expecting the 6th field to be the 'Left-Lateral-Ventricle' string and the %*s to skip the space, which occupies the first column of data. I'm fairly new to matlab, so am not sure if this is correct or not. 

When I remove the %*s, then the error changes from the 5th field to the 6th field.
0
Reply corinna 9/7/2010 11:05:06 PM

On 10-09-07 05:59 PM, corinna wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <i66fai$bip$1@canopus.cc.umanitoba.ca>...
>> On 10-09-07 05:38 PM, corinna bauer wrote:
>> > I am trying to read in a csv file (see below for example), but I keep
>> > getting this error message:
>> > ??? Error using ==> dataread
>> > Trouble reading floating point number from file (row 2, field 5) ==>
>> > Left-Inf-Lat-Vent
>> >
>> > Here is my script:
>> >
>> [a,b,c,d,e,f,g,h,i,j]=textread('/home/corinna/blstats/subject1.pet.segstats.csv','%*s%2d%4f%5f%5f%32q%f%f%f%f%f',...
>>
>> >
>> > 95,'headerlines',52);
>> >
>> > The first part of the .csv file looks like this:
>> > 1 4 6258 6258.0 Left-Lateral-Ventricle 11979.8975 2929.6318 8061.0000
>> > 26612.0000 18551.0000
>> > 2 5 630 630.0 Left-Inf-Lat-Vent 14453.3525
>> > 1466.4132 11027.0000 18501.0000 7474.0000
>>
>> What were you expecting? Your 5th field specifier in the format is %5f
>> which is a format for a floating point number, but your fifth field is
>> 'Left-Lateral-Ventricle' which is definitely not a floating point number.
>>
>> Were you expecting the initial %*s to somehow read from the beginning
>> of the line to the end of the 'Left-Lateral-Ventricle' string?
>
> I was expecting the initial %*s to skip the space at the beginning of
> each line. If I remove the %*s then the error changes to the 6th field,
> rather than the 5th. I'm new to matlab and not really sure which formats
> to use.

The %s format skips leading whitespace _before_ it begins to read characters, 
so with the %*s in there, the first two blanks on the line would be skipped as 
whitespace and then the '1' or '2' etc would be recognized as a string.
The %2d would start after that without having read all of the second column of 
numbers... and problems cascade from there. The %5f after that would read all 
blanks...

As you do not appear to have any fields that run together, I suggest you use
'%d%f%f%f%s%f%f%f%f%f'

In this case, where there are no widths on the formats, leading whitespace 
will automatically be skipped before reading each numeric format.
0
Reply roberson (2852) 9/7/2010 11:12:44 PM

Walter Roberson <roberson@hushmail.com> wrote in message <i66h0j$dr2$1@canopus.cc.umanitoba.ca>...
> On 10-09-07 05:59 PM, corinna wrote:
> > Walter Roberson <roberson@hushmail.com> wrote in message
> > <i66fai$bip$1@canopus.cc.umanitoba.ca>...
> >> On 10-09-07 05:38 PM, corinna bauer wrote:
> >> > I am trying to read in a csv file (see below for example), but I keep
> >> > getting this error message:
> >> > ??? Error using ==> dataread
> >> > Trouble reading floating point number from file (row 2, field 5) ==>
> >> > Left-Inf-Lat-Vent
> >> >
> >> > Here is my script:
> >> >
> >> [a,b,c,d,e,f,g,h,i,j]=textread('/home/corinna/blstats/subject1.pet.segstats.csv','%*s%2d%4f%5f%5f%32q%f%f%f%f%f',...
> >>
> >> >
> >> > 95,'headerlines',52);
> >> >
> >> > The first part of the .csv file looks like this:
> >> > 1 4 6258 6258.0 Left-Lateral-Ventricle 11979.8975 2929.6318 8061.0000
> >> > 26612.0000 18551.0000
> >> > 2 5 630 630.0 Left-Inf-Lat-Vent 14453.3525
> >> > 1466.4132 11027.0000 18501.0000 7474.0000
> >>
> >> What were you expecting? Your 5th field specifier in the format is %5f
> >> which is a format for a floating point number, but your fifth field is
> >> 'Left-Lateral-Ventricle' which is definitely not a floating point number.
> >>
> >> Were you expecting the initial %*s to somehow read from the beginning
> >> of the line to the end of the 'Left-Lateral-Ventricle' string?
> >
> > I was expecting the initial %*s to skip the space at the beginning of
> > each line. If I remove the %*s then the error changes to the 6th field,
> > rather than the 5th. I'm new to matlab and not really sure which formats
> > to use.
> 
> The %s format skips leading whitespace _before_ it begins to read characters, 
> so with the %*s in there, the first two blanks on the line would be skipped as 
> whitespace and then the '1' or '2' etc would be recognized as a string.
> The %2d would start after that without having read all of the second column of 
> numbers... and problems cascade from there. The %5f after that would read all 
> blanks...
> 
> As you do not appear to have any fields that run together, I suggest you use
> '%d%f%f%f%s%f%f%f%f%f'
> 
> In this case, where there are no widths on the formats, leading whitespace 
> will automatically be skipped before reading each numeric format.

Thanks, that seems to wok, although it reads the data in scientific format:
  out: 1.197990e+04
  out: 1.445335e+04
  out: 1.733911e+04
  out: 1.846109e+04
How do I get it to be in regular format (i.e. 1197.99)?
0
Reply corinnab83 (2) 9/8/2010 1:59:07 PM

On 10-09-08 08:59 AM, corinna wrote:

> Thanks, that seems to wok, although it reads the data in scientific format:
> out: 1.197990e+04
> out: 1.445335e+04
> out: 1.733911e+04
> out: 1.846109e+04
> How do I get it to be in regular format (i.e. 1197.99)?

textscan does not read into scientific format, but your display format might 
be set to show in scientific format. Try commanding

format short


0
Reply roberson (2852) 9/8/2010 3:31:17 PM

6 Replies
480 Views

(page loaded in 0.053 seconds)

Similiar Articles:













7/20/2012 7:11:54 PM


Reply: