0

for instance I had set the display format of a program at the very beginning such as format shortG and then I would like to use the fprintf command to display a certain values.

For example I have

x = 1.23456789

y = 12.3456789

If under format shortG it will show x = 1.2346 and y = 12.346. My question is what format I should use when using the fprintf because like if using %.4f y will equal to 12.3457 which is not what I want. Thanks for every single help.

4

1 回答 1

2

使用g代替f

>> fprintf('%.5g\n',y)
12.346
>> fprintf('%.5g\n',x)
1.2346
于 2013-04-10T15:29:06.907 回答