Centering output on Command Window

8 views (last 30 days)
I have a few strings that are displayed onto the command window to tell the user of my program some instructions and information. I want all of these strings centered in the comman window. Ive tried afew things but to no avail. Anyone have any suggestions?
  1 Comment
Jan
Jan on 21 Mar 2012
Please post what you have tried and which problems have occurred.

Sign in to comment.

Accepted Answer

Jan
Jan on 21 Mar 2012
Msg = 'hello';
CmdWinSize = get(0, 'CommandWindowSize');
Height = CmdWinSize(1); % Thanks, Friedrich! [EDITED]
Width = CmdWinSize(2);
clc;
fprintf(repmat('\n', floor(Height / 2) - 1);
fprintf(blanks(floor(Width - length(Msg)) / 2));
fprintf('%s\n', Msg);
  2 Comments
Friedrich
Friedrich on 21 Mar 2012
Small typo. It s hould be
Width = CmdWinSize(1);
Jan
Jan on 21 Mar 2012
Thanks, Friedrich.
I do not have access to Matlab currently, such that the code is not tested.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!