Centering output on Command Window

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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2012년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by