Home MATLAB is rounding off to nearest integer
Reply: 1

MATLAB is rounding off to nearest integer

Abdul kareem
Abdul kareem Published in 2017-05-08 04:11:22Z

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));

But instead of giving me exact floating point values MATLAB is converting it to nearest integers. Please help me in getting the exact values.

gnovice Reply to 2017-05-08 04:16:30Z

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
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.418892 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO