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

10 次查看(过去 30 天)
For example:
Thank you.

回答(3 个)

Fangjun Jiang
Fangjun Jiang 2011-4-26
a=[36.897, 1369.4587
0.3, 2.5
1, 2
25.8,3.125];
b=num2str(a);
b(:,8:12)=[]

Walter Roberson
Walter Roberson 2011-4-26
sprintf('%20.2f ', a)
  3 个评论

请先登录,再进行评论。


Fangjun Jiang
Fangjun Jiang 2011-4-26
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.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by