Quantcast

textscan wanted

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

textscan wanted

Dr. Johannes Zellner
Hi,

I've a bunch of matlab files which use textscan.

I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().

Does anyone have a textscan implementation?

regards,

--
Johannes.

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

bpabbott
Administrator
On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:

> Hi,
>
> I've a bunch of matlab files which use textscan.
>
> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>
> Does anyone have a textscan implementation?
>
> regards,
>
> --
> Johannes.

I've opened a ticket in the bug tracker.

        https://savannah.gnu.org/bugs/index.php?31380

For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.

The syntax for ML's textscan is ...

C = textscan (fid, 'format')
C = textscan (fid, 'format', N)
C = textscan (fid, 'format', 'param', value)
C = textscan (fid, 'format', N, 'param', value)
C = textscan (str, ...)
[C, position] = textscan (...)

If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.

C = textscan (fid, 'format')
C = textscan (fid, 'format', 'param', value)
C = textscan (str, ...)

Would that be useful to you?

Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

Dr. Johannes Zellner
Ben,

thanks for the quick response.
It would be more useful, if it would also allow the input parameter N.

regards,

--
Johannes


2010/10/20 Ben Abbott <[hidden email]>
On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:

> Hi,
>
> I've a bunch of matlab files which use textscan.
>
> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>
> Does anyone have a textscan implementation?
>
> regards,
>
> --
> Johannes.

I've opened a ticket in the bug tracker.

       https://savannah.gnu.org/bugs/index.php?31380

For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.

The syntax for ML's textscan is ...

C = textscan (fid, 'format')
C = textscan (fid, 'format', N)
C = textscan (fid, 'format', 'param', value)
C = textscan (fid, 'format', N, 'param', value)
C = textscan (str, ...)
[C, position] = textscan (...)

If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.

C = textscan (fid, 'format')
C = textscan (fid, 'format', 'param', value)
C = textscan (str, ...)

Would that be useful to you?

Ben



_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

bpabbott
Administrator

On Oct 20, 2010, at 1:39 PM, Dr. Johannes Zellner wrote:

> 2010/10/20 Ben Abbott <[hidden email]>
> On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:
>
>> > Hi,
>> >
>> > I've a bunch of matlab files which use textscan.
>> >
>> > I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>> >
>> > Does anyone have a textscan implementation?
>> >
>> > regards,
>> >
>> > --
>> > Johannes.
>>
>> I've opened a ticket in the bug tracker.
>>
>>        https://savannah.gnu.org/bugs/index.php?31380
>>
>> For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.
>>
>> The syntax for ML's textscan is ...
>>
>> C = textscan (fid, 'format')
>> C = textscan (fid, 'format', N)
>> C = textscan (fid, 'format', 'param', value)
>> C = textscan (fid, 'format', N, 'param', value)
>> C = textscan (str, ...)
>> [C, position] = textscan (...)
>>
>> If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.
>>
>> C = textscan (fid, 'format')
>> C = textscan (fid, 'format', 'param', value)
>> C = textscan (str, ...)
>>
>> Would that be useful to you?
>>
>> Ben
>
> Ben,
>
> thanks for the quick response.
> It would be more useful, if it would also allow the input parameter N.
>
> regards,

Ok. Can you provide a simple example with both an input file and a script that uses textscan() with the parameter N to read some data?

Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

bpabbott
Administrator
On Oct 20, 2010, at 1:55 PM, Ben Abbott wrote:

> On Oct 20, 2010, at 1:39 PM, Dr. Johannes Zellner wrote:
>
>> 2010/10/20 Ben Abbott <[hidden email]>
>> On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:
>>
>>>> Hi,
>>>>
>>>> I've a bunch of matlab files which use textscan.
>>>>
>>>> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>>>>
>>>> Does anyone have a textscan implementation?
>>>>
>>>> regards,
>>>>
>>>> --
>>>> Johannes.
>>>
>>> I've opened a ticket in the bug tracker.
>>>
>>>       https://savannah.gnu.org/bugs/index.php?31380
>>>
>>> For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.
>>>
>>> The syntax for ML's textscan is ...
>>>
>>> C = textscan (fid, 'format')
>>> C = textscan (fid, 'format', N)
>>> C = textscan (fid, 'format', 'param', value)
>>> C = textscan (fid, 'format', N, 'param', value)
>>> C = textscan (str, ...)
>>> [C, position] = textscan (...)
>>>
>>> If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.
>>>
>>> C = textscan (fid, 'format')
>>> C = textscan (fid, 'format', 'param', value)
>>> C = textscan (str, ...)
>>>
>>> Would that be useful to you?
>>>
>>> Ben
>>
>> Ben,
>>
>> thanks for the quick response.
>> It would be more useful, if it would also allow the input parameter N.
>>
>> regards,
>
> Ok. Can you provide a simple example with both an input file and a script that uses textscan() with the parameter N to read some data?
>
> Ben
I found some simple examples on the web, and made an attempt at implementing the function.

I'd appreciate it if you can try the attached textscan.m and let us know if it works for you.

Ben




_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

textscan.m (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

Dr. Johannes Zellner
Ben,

thanks // where do I get strread which is used in your function?
--
Johannes


2010/10/20 Ben Abbott <[hidden email]>
On Oct 20, 2010, at 1:55 PM, Ben Abbott wrote:

> On Oct 20, 2010, at 1:39 PM, Dr. Johannes Zellner wrote:
>
>> 2010/10/20 Ben Abbott <[hidden email]>
>> On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:
>>
>>>> Hi,
>>>>
>>>> I've a bunch of matlab files which use textscan.
>>>>
>>>> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>>>>
>>>> Does anyone have a textscan implementation?
>>>>
>>>> regards,
>>>>
>>>> --
>>>> Johannes.
>>>
>>> I've opened a ticket in the bug tracker.
>>>
>>>       https://savannah.gnu.org/bugs/index.php?31380
>>>
>>> For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.
>>>
>>> The syntax for ML's textscan is ...
>>>
>>> C = textscan (fid, 'format')
>>> C = textscan (fid, 'format', N)
>>> C = textscan (fid, 'format', 'param', value)
>>> C = textscan (fid, 'format', N, 'param', value)
>>> C = textscan (str, ...)
>>> [C, position] = textscan (...)
>>>
>>> If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.
>>>
>>> C = textscan (fid, 'format')
>>> C = textscan (fid, 'format', 'param', value)
>>> C = textscan (str, ...)
>>>
>>> Would that be useful to you?
>>>
>>> Ben
>>
>> Ben,
>>
>> thanks for the quick response.
>> It would be more useful, if it would also allow the input parameter N.
>>
>> regards,
>
> Ok. Can you provide a simple example with both an input file and a script that uses textscan() with the parameter N to read some data?
>
> Ben

I found some simple examples on the web, and made an attempt at implementing the function.

I'd appreciate it if you can try the attached textscan.m and let us know if it works for you.

Ben






_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

bpabbott
Administrator
For the developer's sources, strread is part of the core. I just checked the sources, it was added 12 months ago.

        http://hg.savannah.gnu.org/hgweb/octave/log/d3eaaa7c6762/scripts/io/strread.m

I don't know if it can be transplanted into prior versions and work correctly.

Ben


On Oct 21, 2010, at 2:52 AM, Dr. Johannes Zellner wrote:

> Ben,
>
> thanks // where do I get strread which is used in your function?
> --
> Johannes
>
>
> 2010/10/20 Ben Abbott <[hidden email]>
> On Oct 20, 2010, at 1:55 PM, Ben Abbott wrote:
>
> > On Oct 20, 2010, at 1:39 PM, Dr. Johannes Zellner wrote:
> >
> >> 2010/10/20 Ben Abbott <[hidden email]>
> >> On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:
> >>
> >>>> Hi,
> >>>>
> >>>> I've a bunch of matlab files which use textscan.
> >>>>
> >>>> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
> >>>>
> >>>> Does anyone have a textscan implementation?
> >>>>
> >>>> regards,
> >>>>
> >>>> --
> >>>> Johannes.
> >>>
> >>> I've opened a ticket in the bug tracker.
> >>>
> >>>       https://savannah.gnu.org/bugs/index.php?31380
> >>>
> >>> For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.
> >>>
> >>> The syntax for ML's textscan is ...
> >>>
> >>> C = textscan (fid, 'format')
> >>> C = textscan (fid, 'format', N)
> >>> C = textscan (fid, 'format', 'param', value)
> >>> C = textscan (fid, 'format', N, 'param', value)
> >>> C = textscan (str, ...)
> >>> [C, position] = textscan (...)
> >>>
> >>> If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.
> >>>
> >>> C = textscan (fid, 'format')
> >>> C = textscan (fid, 'format', 'param', value)
> >>> C = textscan (str, ...)
> >>>
> >>> Would that be useful to you?
> >>>
> >>> Ben
> >>
> >> Ben,
> >>
> >> thanks for the quick response.
> >> It would be more useful, if it would also allow the input parameter N.
> >>
> >> regards,
> >
> > Ok. Can you provide a simple example with both an input file and a script that uses textscan() with the parameter N to read some data?
> >
> > Ben
>
> I found some simple examples on the web, and made an attempt at implementing the function.
>
> I'd appreciate it if you can try the attached textscan.m and let us know if it works for you.
>
> Ben
>
>
>
>
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

Liam Groener
In reply to this post by bpabbott

On Oct 20, 2010, at 3:03 AM, Ben Abbott wrote:

> On Oct 20, 2010, at 1:55 PM, Ben Abbott wrote:
>
>> On Oct 20, 2010, at 1:39 PM, Dr. Johannes Zellner wrote:
>>
>>> 2010/10/20 Ben Abbott <[hidden email]>
>>> On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:
>>>
>>>>> Hi,
>>>>>
>>>>> I've a bunch of matlab files which use textscan.
>>>>>
>>>>> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>>>>>
>>>>> Does anyone have a textscan implementation?
>>>>>
>>>>> regards,
>>>>>
>>>>> --
>>>>> Johannes.
>>>>
>>>> I've opened a ticket in the bug tracker.
>>>>
>>>>      https://savannah.gnu.org/bugs/index.php?31380
>>>>
>>>> For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.
>>>>
>>>> The syntax for ML's textscan is ...
>>>>
>>>> C = textscan (fid, 'format')
>>>> C = textscan (fid, 'format', N)
>>>> C = textscan (fid, 'format', 'param', value)
>>>> C = textscan (fid, 'format', N, 'param', value)
>>>> C = textscan (str, ...)
>>>> [C, position] = textscan (...)
>>>>
>>>> If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.
>>>>
>>>> C = textscan (fid, 'format')
>>>> C = textscan (fid, 'format', 'param', value)
>>>> C = textscan (str, ...)
>>>>
>>>> Would that be useful to you?
>>>>
>>>> Ben
>>>
>>> Ben,
>>>
>>> thanks for the quick response.
>>> It would be more useful, if it would also allow the input parameter N.
>>>
>>> regards,
>>
>> Ok. Can you provide a simple example with both an input file and a script that uses textscan() with the parameter N to read some data?
>>
>> Ben
>
> I found some simple examples on the web, and made an attempt at implementing the function.
>
> I'd appreciate it if you can try the attached textscan.m and let us know if it works for you.
>
> Ben
>
> <textscan.m>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Hi Ben,

I downloaded the textscan.m and strread.m from your emails and tried the following simple script from a Matlab book using Octave 3.2.3:

B = [30 40 60 70];
fid = fopen('myoutput','w');
fprintf(fid,'%g miles/hr = %g kilometers/hr\n',[B;8*B/5]);
fclose(fid);

fopen('myoutput','r');
X = fscanf(fid,'%f miles/hr = %f kilometers/hr')
C = textscan(fid,'%f miles/hr = %f kilometers/hr')
fclose(fid);

This was the output:

X =

    30
    48
    40
    64
    60
    96
    70
   112

error: A(I): Index exceeds matrix dimension.
error: called from:
error:   /Users/liamg/mFiles/textscan.m at line 60, column 3
error:   /Users/liamg/mFiles/tst.m at line 8, column 3

The file "myoutput" was written correctly.

Liam


_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

bpabbott
Administrator
On Oct 21, 2010, at 9:52 AM, Liam Groener wrote:

> On Oct 20, 2010, at 3:03 AM, Ben Abbott wrote:
>
>> On Oct 20, 2010, at 1:55 PM, Ben Abbott wrote:
>>
>>> On Oct 20, 2010, at 1:39 PM, Dr. Johannes Zellner wrote:
>>>
>>>> 2010/10/20 Ben Abbott <[hidden email]>
>>>> On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:
>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I've a bunch of matlab files which use textscan.
>>>>>>
>>>>>> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>>>>>>
>>>>>> Does anyone have a textscan implementation?
>>>>>>
>>>>>> regards,
>>>>>>
>>>>>> --
>>>>>> Johannes.
>>>>>
>>>>> I've opened a ticket in the bug tracker.
>>>>>
>>>>>     https://savannah.gnu.org/bugs/index.php?31380
>>>>>
>>>>> For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.
>>>>>
>>>>> The syntax for ML's textscan is ...
>>>>>
>>>>> C = textscan (fid, 'format')
>>>>> C = textscan (fid, 'format', N)
>>>>> C = textscan (fid, 'format', 'param', value)
>>>>> C = textscan (fid, 'format', N, 'param', value)
>>>>> C = textscan (str, ...)
>>>>> [C, position] = textscan (...)
>>>>>
>>>>> If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.
>>>>>
>>>>> C = textscan (fid, 'format')
>>>>> C = textscan (fid, 'format', 'param', value)
>>>>> C = textscan (str, ...)
>>>>>
>>>>> Would that be useful to you?
>>>>>
>>>>> Ben
>>>>
>>>> Ben,
>>>>
>>>> thanks for the quick response.
>>>> It would be more useful, if it would also allow the input parameter N.
>>>>
>>>> regards,
>>>
>>> Ok. Can you provide a simple example with both an input file and a script that uses textscan() with the parameter N to read some data?
>>>
>>> Ben
>>
>> I found some simple examples on the web, and made an attempt at implementing the function.
>>
>> I'd appreciate it if you can try the attached textscan.m and let us know if it works for you.
>>
>> Ben
>>
>> <textscan.m>
>
> Hi Ben,
>
> I downloaded the textscan.m and strread.m from your emails and tried the following simple script from a Matlab book using Octave 3.2.3:
>
> B = [30 40 60 70];
> fid = fopen('myoutput','w');
> fprintf(fid,'%g miles/hr = %g kilometers/hr\n',[B;8*B/5]);
> fclose(fid);
>
> fopen('myoutput','r');
> X = fscanf(fid,'%f miles/hr = %f kilometers/hr')
> C = textscan(fid,'%f miles/hr = %f kilometers/hr')
> fclose(fid);
>
> This was the output:
>
> X =
>
>    30
>    48
>    40
>    64
>    60
>    96
>    70
>   112
>
> error: A(I): Index exceeds matrix dimension.
> error: called from:
> error:   /Users/liamg/mFiles/textscan.m at line 60, column 3
> error:   /Users/liamg/mFiles/tst.m at line 8, column 3
>
> The file "myoutput" was written correctly.
>
> Liam


I tried the example above in Matlab. The result for C was ...

C =   [0x1 double]    [0x1 double]

If I commend out "X = fscan (...)" then I get

C =   [4x1 double]    [4x1 double]

>> C{1}

ans =

    30
    40
    60
    70

>> C{2}

ans =

    48
    64
    96
   112

I modified the example as ...

B = [30 40 60 70];
fid = fopen ('myoutput','w');
fmt = '%g miles/hr = %g kilometers/hr\n';
str = sprintf (fmt, [B;8*B/5]);
fprintf (fid, '%s', str);
fclose (fid);

fopen ('myoutput','r');
fmt = '%f miles/hr = %f kilometers/hr';
C = textscan (fid, fmt);
fclose (fid);

c = cell (1, 2);
[c{:}] = strread (str, fmt);

With ML, both textscan() and strread() give the same result.

>From that I infer that the problem is with strread(). I'll take a look at fixing that.

Ben
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

bpabbott
Administrator

On Oct 21, 2010, at 11:36 AM, Ben Abbott wrote:

> On Oct 21, 2010, at 9:52 AM, Liam Groener wrote:
>
>> On Oct 20, 2010, at 3:03 AM, Ben Abbott wrote:
>>
>>> On Oct 20, 2010, at 1:55 PM, Ben Abbott wrote:
>>>
>>>> On Oct 20, 2010, at 1:39 PM, Dr. Johannes Zellner wrote:
>>>>
>>>>> 2010/10/20 Ben Abbott <[hidden email]>
>>>>> On Oct 20, 2010, at 4:53 AM, Dr. Johannes Zellner wrote:
>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I've a bunch of matlab files which use textscan.
>>>>>>>
>>>>>>> I don't want to replace all textscan calls with something like fscanf but I'd rather like to have an octave function which implements textscan().
>>>>>>>
>>>>>>> Does anyone have a textscan implementation?
>>>>>>>
>>>>>>> regards,
>>>>>>>
>>>>>>> --
>>>>>>> Johannes.
>>>>>>
>>>>>> I've opened a ticket in the bug tracker.
>>>>>>
>>>>>>    https://savannah.gnu.org/bugs/index.php?31380
>>>>>>
>>>>>> For now, have you looked at using textread() instead? Unfortunately, textread() is not fully compatible with the ML version.
>>>>>>
>>>>>> The syntax for ML's textscan is ...
>>>>>>
>>>>>> C = textscan (fid, 'format')
>>>>>> C = textscan (fid, 'format', N)
>>>>>> C = textscan (fid, 'format', 'param', value)
>>>>>> C = textscan (fid, 'format', N, 'param', value)
>>>>>> C = textscan (str, ...)
>>>>>> [C, position] = textscan (...)
>>>>>>
>>>>>> If you don't require the input "N", it should be straight forward to modify scantext() to implement textscan(). A quick fix would support the limited syntax below.
>>>>>>
>>>>>> C = textscan (fid, 'format')
>>>>>> C = textscan (fid, 'format', 'param', value)
>>>>>> C = textscan (str, ...)
>>>>>>
>>>>>> Would that be useful to you?
>>>>>>
>>>>>> Ben
>>>>>
>>>>> Ben,
>>>>>
>>>>> thanks for the quick response.
>>>>> It would be more useful, if it would also allow the input parameter N.
>>>>>
>>>>> regards,
>>>>
>>>> Ok. Can you provide a simple example with both an input file and a script that uses textscan() with the parameter N to read some data?
>>>>
>>>> Ben
>>>
>>> I found some simple examples on the web, and made an attempt at implementing the function.
>>>
>>> I'd appreciate it if you can try the attached textscan.m and let us know if it works for you.
>>>
>>> Ben
>>>
>>> <textscan.m>
>>
>> Hi Ben,
>>
>> I downloaded the textscan.m and strread.m from your emails and tried the following simple script from a Matlab book using Octave 3.2.3:
>>
>> B = [30 40 60 70];
>> fid = fopen('myoutput','w');
>> fprintf(fid,'%g miles/hr = %g kilometers/hr\n',[B;8*B/5]);
>> fclose(fid);
>>
>> fopen('myoutput','r');
>> X = fscanf(fid,'%f miles/hr = %f kilometers/hr')
>> C = textscan(fid,'%f miles/hr = %f kilometers/hr')
>> fclose(fid);
>>
>> This was the output:
>>
>> X =
>>
>>   30
>>   48
>>   40
>>   64
>>   60
>>   96
>>   70
>>  112
>>
>> error: A(I): Index exceeds matrix dimension.
>> error: called from:
>> error:   /Users/liamg/mFiles/textscan.m at line 60, column 3
>> error:   /Users/liamg/mFiles/tst.m at line 8, column 3
>>
>> The file "myoutput" was written correctly.
>>
>> Liam
>
>
> I tried the example above in Matlab. The result for C was ...
>
> C =   [0x1 double]    [0x1 double]
>
> If I commend out "X = fscan (...)" then I get
>
> C =   [4x1 double]    [4x1 double]
>
>>> C{1}
>
> ans =
>
>    30
>    40
>    60
>    70
>
>>> C{2}
>
> ans =
>
>    48
>    64
>    96
>   112
>
> I modified the example as ...
>
> B = [30 40 60 70];
> fid = fopen ('myoutput','w');
> fmt = '%g miles/hr = %g kilometers/hr\n';
> str = sprintf (fmt, [B;8*B/5]);
> fprintf (fid, '%s', str);
> fclose (fid);
>
> fopen ('myoutput','r');
> fmt = '%f miles/hr = %f kilometers/hr';
> C = textscan (fid, fmt);
> fclose (fid);
>
> c = cell (1, 2);
> [c{:}] = strread (str, fmt);
>
> With ML, both textscan() and strread() give the same result.
>
>> From that I infer that the problem is with strread(). I'll take a look at fixing that.
>
> Ben
I've attached updated versions of strread.m and textscan.m

If the format includes regular expressions then these won't work. Otherwise, the should be ok.

If no problems are found, I'll move this thread to the developers list.

Ben




_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

strread.m (8K) Download Attachment
textscan.m (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

redbaronMIT

 I added both files to my Windows 3.2.4 Octave version.  I tested them with the "help COMMAND" and got the following error for strread ("help textscan" returned the help-text fine)

help strread
>>>parse error near line 189 of file D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2
.4\m\dev\strread.m

  syntax error

>>>   [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+");
       ^

parse error near line 189 of file D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\
m\dev\strread.m

  syntax error

>>>   [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+");
       ^

error: called from:
error:   D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\help\help.m at line 55,
 column 17


Let me know if this has a possible fix.
-Jason


----
Quoted message:

I've attached updated versions of strread.m and textscan.m

If the format includes regular expressions then these won't work. Otherwise, the should be ok.

If no problems are found, I'll move this thread to the developers list.

Ben




_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

tmacchant
Hello

For my case

octave-3.2.4.exe:1> help strread
error: help: `strread' not found.


Do you know the oct2mat issue for octave 3.2.4 for windows?
Please see;
http://wiki.octave.org/wiki.pl?OctaveForWindows
 1. Standalone ports
  1.1. Octave 3.2.4 for Windows MinGW32
   Additional important topics found after the release:

Regards

Tatsuro





--- On Mon, 2011/8/29, redbaronMIT <[hidden email]> wrote:

>
>  I added both files to my Windows 3.2.4 Octave version.  I tested them with
> the "help COMMAND" and got the following error for strread ("help textscan"
> returned the help-text fine)
>
> help strread
> >>>parse error near line 189 of file
> D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2
> .4\m\dev\strread.m
>
>   syntax error
>
> >>>   [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+");
>        ^
>
> parse error near line 189 of file
> D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\
> m\dev\strread.m
>
>   syntax error
>
> >>>   [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+");
>        ^
>
> error: called from:
> error:   D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\help\help.m at line
> 55,
>  column 17
>
>
> Let me know if this has a possible fix.
> -Jason
>
>
> ----
> Quoted message:
>
> I've attached updated versions of strread.m and textscan.m
>
> If the format includes regular expressions then these won't work. Otherwise,
> the should be ok.
>
> If no problems are found, I'll move this thread to the developers list.
>
> Ben
>
>
>
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
>
>
> --
> View this message in context: http://octave.1599824.n4.nabble.com/textscan-wanted-tp3002808p3775352.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://mailman.cae.wisc.edu/listinfo/help-octave
>
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: textscan wanted

bpabbott
Administrator
In reply to this post by redbaronMIT
On Aug 28, 2011, at 10:49 PM, redbaronMIT wrote:

>

> ----
> Quoted message:
>>
>> I've attached updated versions of strread.m and textscan.m
>>
>> If the format includes regular expressions then these won't work. Otherwise,
>> the should be ok.
>>
>> If no problems are found, I'll move this thread to the developers list.
>>
>> Ben
>
> I added both files to my Windows 3.2.4 Octave version.  I tested them with
> the "help COMMAND" and got the following error for strread ("help textscan"
> returned the help-text fine)
>
> help strread
>>>> parse error near line 189 of file
> D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2
> .4\m\dev\strread.m
>
>  syntax error
>
>>>>  [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+");
>       ^
>
> parse error near line 189 of file
> D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\
> m\dev\strread.m
>
>  syntax error
>
>>>>  [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+");
>       ^
>
> error: called from:
> error:   D:\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\help\help.m at line
> 55,
> column 17
>
> Let me know if this has a possible fix.
> -Jason

I don't have a copy of 3.2.4 to verify my suspicion on, but I think the "~" character in the output was introduced after version 3.2.4.

Thus, If you replace the tilde's with some place-holder variables the syntax error should go away.

        [foobar1,foobar2,foobar3, fmt_words] =  regexp (formatstr, "[^\\s]+");

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Loading...