Displaying information from MATLAB without a line feed

前端 未结 1 1182
陌清茗
陌清茗 2021-02-12 22:48

Is there any way to output/display information from a MATLAB program without an ending line feed?

My MATLAB program outputs a number a bit now and then. Between outputti

相关标签:
1条回答
  • 2021-02-12 23:16

    The fprintf function does not add a line feed unless you explicitly tell it to. Omit the fid argument to have it print to the Command Window.

    fprintf('Doing stuff... ');
    for i = 1:5
        fprintf('%d ', i);
        % do some work on that pass...
    end
    fprintf(' done.\n'); % That \n explicitly adds the linefeed
    

    Using sprintf won't quite work: it creates a string without a line feed, but then if you use disp() or omit the semicolon, disp's own display logic will add a line feed.

    0 讨论(0)
提交回复
热议问题