当我使用Matlab从Bloomberg中获取数据时,如何设置小数位?
我正在使用Matlab历史loggingfunction从布隆伯格检索数据,似乎Matlab设置了4位小数作为默认值。 这有时与我从Excel中提取的数据不一致。 例如:
这里是Matlab代码:
[d, sec] = history(c, 'TY1 Comdty', 'PX_LAST', '1982-5-6', '1982-5-6')
我从Matlab和Excel得到不同的结果:
Date 5/6/1982 Excel 72.96875 Matlab 72.9688
有没有办法设置历史function的财产,得到72.96875,而不是72.9688?
Excel没有象用所需格式显示数字一样好的解决scheme。
在Matlab中,您可以将format long
设置为小数点后15位, format short
为小数点后4位。 这就是你所拥有的一切。
尽pipe如此,两种解决方法。 第一round
使用
(1) format long %define 15 digit precision xround = @(x,d) round(x/d)*d; %rounding function with d format a = xround(72.96875, 0.00001) %rounding your value by calling 'xround' function
它给
a = 72.968750000000000
第二个解决方法打印一个string(不是标量)
(2) sprintf('%.5f', 72.96875)
它给
ans = 72.96875
要将Excel与Matlab匹配,可以键入
[d, sec] = history(c, 'TY1 Comdty', 'PX_LAST', '1982-5-6', '1982-5-6'); d = xround(d, 0.00001);
使用format
命令将显示设置为所需的有效位数: http : //www.mathworks.co.uk/help/matlab/ref/format.html