bugGNU Octave - Bugs: bug #63353, Error in fscanf when maximum field...


bug #63353: Error in fscanf when maximum field width is specified and '%f' conversion used

Submitter:  José Luis García Pallero <jgpallero>
Submitted:  Sat 12 Nov 2022 05:17:04 PM UTC
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  José Luis García Pallero Open/Closed:  * Open
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Tue 15 Nov 2022 04:40:24 PM UTC, comment #2: 

If I had to take a guess, I think Matlab divides the input stream based on the field width and then applies the conversion to each chunk of input.  Octave, however, seems to apply the conversion to the input and then move to whatever remains of the input stream.

Matlab behavior:

v = sscanf ('1.234.567', '%3f')
v =

Octave behavior:

v = sscanf ('1.234.567', '%3f')
v =

Rik <rik5>
Group administrator
Tue 15 Nov 2022 04:31:09 PM UTC, comment #1: 

Confirmed.  The behavior is also dependent on the type of the conversion.  If the conversion is to an integer type then the function behaves as expected.  For example,

[v,n] = sscanf (a, '%3d')
v =


n = 3

It is only when a floating point type such as '%f', '%e', '%g' is used that there is a problem.

Rik <rik5>
Group administrator
Sat 12 Nov 2022 05:17:04 PM UTC, original submission:  

Octave documentation states the maximum field width option in the input conversion syntax for fscanf and sscanf functions (https://docs.octave.org/latest/Input-Conversion-Syntax.html). But this example works in Matlab:

a = '1234567';
[val,n] = sscanf(a,'%3f',[1 Inf])
val =
   123   456     7
n =

but not in Octave:

a = '1234567';
[val,n] = sscanf(a,'%3f',[1 Inf])
val = 1234567
n = 1

José Luis García Pallero <jgpallero>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jgpallero (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.


    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-11-15 rik5 StatusNone Confirmed
        SummaryError in fscanf when maximum field width is specified Error in fscanf when maximum field width is specified and '%f' conversion used

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code