MATLAB 四舍五入到最接近的整数

MATLAB is rounding off to nearest integer

我有一个 1x50000 大小矩阵 v,我想将其转换为零均值和单位方差:

x = ((v-mean(v))/std2(v));

但是 MATLAB 没有给我精确的浮点值,而是将其转换为最接近的整数。请帮助我获得准确的值。

Check the data type for v. I'm sure it's an integer type, using integer arithmetic, which is why the result is an integer. You need to convert it to a floating point type对其进行浮点运算:

v = double(v);              % Convert v to a double-precision float
x = ((v-mean(v))/std2(v));  % Result is now a double as well