How to properly align output text in command window?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Voss
am 28 Dez. 2021
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 Kommentare
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!