How to properly align output text in command window?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Voss
el 28 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!