MATLAB is rounding off to nearest integer

前端 未结 1 961
名媛妹妹
名媛妹妹 2021-01-26 20:12

I have a 1x50000 size matrix v and I want to convert it to zero mean and unit variance:

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

Bu

相关标签:
1条回答
  • 2021-01-26 20:46

    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 to perform floating point operations on it:

    v = double(v);              % Convert v to a double-precision float
    x = ((v-mean(v))/std2(v));  % Result is now a double as well
    
    0 讨论(0)
提交回复
热议问题