How to properly align output text in command window?
조회 수: 13 (최근 30일)
이전 댓글 표시
I use fprintf to print data in command window ( A-data vector, f-data matrix)
for br=1:n
fprintf('\n %4.2f ',A(br));
fprintf(' %4.0f ',f(br,:));
end
and get this:
365.00 962 995 1027 1058 1089 1120 1150 1179
367.00 973 1006 1038 1070 1101 1132 1162 1192
296.50 635 656 677 698 719 739 759 778
96.50 67 70 72 74 76 78 80 82
but, I need it like (nice aligned)
365.00 962 995 1027 1058 1089 1120 1150 1179
367.00 973 1006 1038 1070 1101 1132 1162 1192
296.50 635 656 677 698 719 739 759 778
96.50 67 70 72 74 76 78 80 82
Any suggestions? tnx
댓글 수: 0
답변 (1개)
Voss
2021년 12월 28일
One solution is to use enough characters in your fixed-width format, so that the strings that get fprintf'ed are exactly the same width:
A = [365 367 296.5 96.5];
f = [962 995 1027 1058 1089 1120 1150 1179; ...
973 1006 1038 1070 1101 1132 1162 1192; ...
635 656 677 698 719 739 759 778; ...
67 70 72 74 76 78 80 82];
n = size(f,1);
for br=1:n
fprintf('\n %6.2f ',A(br));
fprintf(' %6.0f ',f(br,:));
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!