Centering output on Command Window

7 ビュー (過去 30 日間)
Michael Joslin
Michael Joslin 2012 年 3 月 21 日
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 件のコメント
Jan
Jan 2012 年 3 月 21 日
Please post what you have tried and which problems have occurred.

サインインしてコメントする。

採用された回答

Jan
Jan 2012 年 3 月 21 日
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 件のコメント
Friedrich
Friedrich 2012 年 3 月 21 日
Small typo. It s hould be
Width = CmdWinSize(1);
Jan
Jan 2012 年 3 月 21 日
Thanks, Friedrich.
I do not have access to Matlab currently, such that the code is not tested.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by