Centering output on Command Window
7 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
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 个评论
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 Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!