**更新我想在matlab.as示例中的浮点部分中仅使用2位数处理float或double
a=23.1234443434343434454545444;
Run Code Online (Sandbox Code Playgroud)
我想如果我使用它是平等的
a=23.12;
Run Code Online (Sandbox Code Playgroud)
在matlab中的任何想法?
我希望功能像圆形(1.95583,2); //在matlab中返回1.95(php函数)
Rod*_*uis 11
如果您想显示只有2位数的值,您可以这样做
>> format bank
>> pi
ans =
3.14
>> rand(4)
ans =
0.81 0.63 0.96 0.96
0.91 0.10 0.96 0.49
0.13 0.28 0.16 0.80
0.91 0.55 0.97 0.14
Run Code Online (Sandbox Code Playgroud)
但这不意味着计算将精度较低进行.
如果后者真的是你想要的(为什么?!),你可以使用像
ppi = single(pi)
Run Code Online (Sandbox Code Playgroud)
为降低精度,或
f = @(x) double(uint64(x*100))/100;
Run Code Online (Sandbox Code Playgroud)
保证2位精度.在最后一种情况下,您必须f
在使用它们之前传递函数中的所有值:
>> ppi = f(pi)
ans =
3.140000000000000
>> f(rand(4))
ans =
0.280000000000000 0.690000000000000 0.440000000000000 0.190000000000000
0.050000000000000 0.320000000000000 0.380000000000000 0.490000000000000
0.100000000000000 0.950000000000000 0.770000000000000 0.450000000000000
0.820000000000000 0.030000000000000 0.800000000000000 0.650000000000000
Run Code Online (Sandbox Code Playgroud)
如果您正在为最后一种情况寻找更优雅的解决方案,请使用Danil建议的定点工具箱.