From: Walter Roberson on
Mike wrote:
> So using US's method I can read in a line that looks like:
>
> # Beam sigy = 0 m, muy = -1e-05 m, dy = 1e-06 m
>
> However, something I didn't realise at the time, some files have the
> string looking like:
>
> # Beam sigy = 0 m, muy = -0.000396 m, dy = 1e-06 m
> OR
> # Beam sigy = 0 m, muy = -5.6e-05 m, dy = 1e-06 m
>
> For the first it will return -0 for the middle number
> and for the 2nd it will return -5 and leave for the middle number.
>
> I'm using
> r=regexp(line,'(?<== )((-)|(\d+)|(e))+','match')
> r=sscanf(sprintf('%s ',r{:}),'%g');
>
> is there a way to make it able to read these 3 formats?

>> t = textscan('# Beam sigy = 0 m, muy = -0.000396 m, dy = 1e-06 m',
'%*[^=]=%fm',3);t{1}
ans =
0
-0.000396
1e-06
>> t = textscan('# Beam sigy = 0 m, muy = -5.6e-05 m, dy = 1e-06 m',
'%*[^=]=%fm',3);t{1}
ans =
0
-5.6e-05
1e-06


Getting a proper regexp format for scientific numbers is tricky.
From: us on
"Mike " <mikejcunningham(a)gmail.com> wrote in message <i2smpp$h7k$1(a)fred.mathworks.com>...
> So using US's method I can read in a line that looks like:
>
> # Beam sigy = 0 m, muy = -1e-05 m, dy = 1e-06 m
>
> However, something I didn't realise at the time, some files have the string looking like:
>
> # Beam sigy = 0 m, muy = -0.000396 m, dy = 1e-06 m
> OR
> # Beam sigy = 0 m, muy = -5.6e-05 m, dy = 1e-06 m
>
> For the first it will return -0 for the middle number
> and
> for the 2nd it will return -5 and leave for the middle number.
>
> I'm using
>
> r=regexp(line,'(?<== )((-)|(\d+)|(e))+','match')
> r=sscanf(sprintf('%s ',r{:}),'%g');
>
> is there a way to make it able to read these 3 formats?
>
> Thanks again,
> --
> Mike

of course...

one of the many solutions

s='# Beam sigy = 0 m, muy = -5.6e-05 m, dy = 1e-06 m';
r=regexp(s,'(?<== )((\d)|(-)|(\.)|(e))+','match');
r=sscanf(sprintf('%s ',r{:}),'%g')
%{
% r =
0
-5.6e-005
1e-006
%}

us
From: Mike on
"us " <us(a)neurol.unizh.ch> wrote in message <i2ugq1$ajb$1(a)fred.mathworks.com>...
> "Mike " <mikejcunningham(a)gmail.com> wrote in message <i2smpp$h7k$1(a)fred.mathworks.com>...
> > So using US's method I can read in a line that looks like:
> >
> > # Beam sigy = 0 m, muy = -1e-05 m, dy = 1e-06 m
> >
> > However, something I didn't realise at the time, some files have the string looking like:
> >
> > # Beam sigy = 0 m, muy = -0.000396 m, dy = 1e-06 m
> > OR
> > # Beam sigy = 0 m, muy = -5.6e-05 m, dy = 1e-06 m
> >
> > For the first it will return -0 for the middle number
> > and
> > for the 2nd it will return -5 and leave for the middle number.
> >
> > I'm using
> >
> > r=regexp(line,'(?<== )((-)|(\d+)|(e))+','match')
> > r=sscanf(sprintf('%s ',r{:}),'%g');
> >
> > is there a way to make it able to read these 3 formats?
> >
> > Thanks again,
> > --
> > Mike
>
> of course...
>
> one of the many solutions
>
> s='# Beam sigy = 0 m, muy = -5.6e-05 m, dy = 1e-06 m';
> r=regexp(s,'(?<== )((\d)|(-)|(\.)|(e))+','match');
> r=sscanf(sprintf('%s ',r{:}),'%g')
> %{
> % r =
> 0
> -5.6e-005
> 1e-006
> %}
>
> us

Thanks a lot of the help guys. Works great.