bugGNU Octave - Bugs: bug #64883, disp is slighly incompatible with...

 
 

bug #64883: disp is slighly incompatible with Matlab

Submitter:  None
Submitted:  Sat 11 Nov 2023 10:19:35 PM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  Undocumented Matlab
Status:  Postponed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 8.3.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 14 Nov 2023 11:16:40 PM UTC, comment #3: 

Referring to https://www.mathworks.com/help/matlab/ref/disp.html, there is nothing stating that disp() will suppress newlines as observed by the OP, so I'm changing this behavior to Undocumented Matlab and reducing priority.

It seems from that page that Matlab's disp() these days intercepts HTML in its string arguments and displays them in the command window as hyperlinks etc. It doesn't seem worth it to implement that in Octave unless someone really wants to carefully parse HTML and display it without introducing security headaches.

If someone wants to close this as Won't Fix, that's OK with me too.

Arun Giridhar <arungiridhar>
Group Member
Tue 14 Nov 2023 09:28:32 PM UTC, comment #2: 

Thanks - fprintf is the solution for both.

fprintf('Counter     ');

for k=1:100
    fprintf('\b\b\b\b%-4d',k);
    pause(0.05);
end
fprintf('\n');


Anonymous
Sun 12 Nov 2023 06:52:13 AM UTC, comment #1: 

That's not because of sprintf. It's because of disp. I use this pattern frequently and it works as intended for me, but I skip the disp-sprintf combination and go straight with printf or fprintf. You can also try printf(sprintf(...)) to verify that the code works with sprintf.

Lowering severity because of the workaround.

If there is an incompatibility with disp's behavior between Matlab and Octave, we can discuss that. Does Matlab always suppress a newline in disp when passed a string that has no newline? Is that documented by them?

Arun Giridhar <arungiridhar>
Group Member
Sat 11 Nov 2023 10:19:35 PM UTC, original submission:  

The following displays a counter that increments in-place in the command window. The previous number is erased and overwritten by the next number. In Matlab you see the word "Counter" followed by a number that changes. In Octave it prints a newline for each character. 


function untitled()

disp('Counter     ');

for k=1:100
    disp(sprintf('\b\b\b\b\b%-4d',k));
    pause(0.05);
end


Anonymous

 

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

Attach Files:
   
   
Comment:
   

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 arungiridhar (Posted a comment)
  •  

    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 group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-11-14 arungiridhar Priority5 - Normal 3 - Low
        Item GroupMatlab Compatibility Undocumented Matlab
        StatusNone Postponed
        Summarysprintf with backspace character inserts newline disp is slighly incompatible with Matlab
    2023-11-12 arungiridhar CategoryNone Octave Function
        Severity3 - Normal 2 - Minor
        Item GroupNone Matlab Compatibility

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code