Disp help. How to pad disp's method of printing variables

1 次查看(过去 30 天)
I have a number of variables, using 'disp' to print out on the command window of matlab. There's like 10 variables and each time I print alot of rows at once. How do I set it to print up to 4 significant figures and if its only 2 or 3 characters, pad with a ' ', or space instead?
eg. 77th row: 215, 84, 201, 55, 131, 0, 0, 0, 0, 0
becomes
77th row: 215, 84, 201, 55, 131, 0, 0, 0, 0, 0
78th row: 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000

采纳的回答

per isakson
per isakson 2015-1-5
编辑:per isakson 2015-1-5
disp doesn't support formatting. Try
data = [ 215, 84, 201, 55, 131, 0, 0, 0, 1000, 1000 ];
row = 77;
fprintf( '%2dth row: %4d, %4d, %4d, %4d, %4d, %4d, %4d, %4d, %4d, %4d\n' ...
, row, data )
it prints
77th row: 215, 84, 201, 55, 131, 0, 0, 0, 1000, 1000
How should the output of "4 significant figures" of 123456 look like?
  1 个评论
lim -
lim - 2015-1-5
Ok thanks it works. 4 significant is just a gauge. I'm assuming it doesn't exceed 9999. I can edit it from here.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by