Filter löschen
Filter löschen

How to add spaces in front of numbers to make their length a constant value

10 Ansichten (letzte 30 Tage)
For example:
Thank you.

Antworten (3)

Fangjun Jiang
Fangjun Jiang am 26 Apr. 2011
a=[36.897, 1369.4587
0.3, 2.5
1, 2
25.8,3.125];
b=num2str(a);
b(:,8:12)=[]
  1 Kommentar
Liqing
Liqing am 26 Apr. 2011
Thanks.
But is there a way to specify that in sprintf? '%10.?f' ?
What should be the '?' then?

Melden Sie sich an, um zu kommentieren.


Walter Roberson
Walter Roberson am 26 Apr. 2011
sprintf('%20.2f ', a)
  3 Kommentare
Liqing
Liqing am 26 Apr. 2011
I guess it should be: sprintf('%20f ', a)
Thanks.

Melden Sie sich an, um zu kommentieren.


Fangjun Jiang
Fangjun Jiang am 26 Apr. 2011
a=[36.897, 1369.4587
0.3, 2.5
1, 2
25.8,3.125];
b=sprintf('%6g%10.8g\n',a')
You might need to adjust the field width and precision based on your larger set of data.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by