MATLAB四舍五入到最接近的整数 [英] MATLAB is rounding off to nearest integer

查看:683
本文介绍了MATLAB四舍五入到最接近的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 1x50000 大小矩阵 v 我希望将其转换为零均值和单位差异:

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

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

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

推荐答案

检查 v 的数据类型。我确定这是一个整数类型,使用整数运算,这就是为什么结果是整数。您需要将其转换为浮点类型对其执行浮点运算:

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

这篇关于MATLAB四舍五入到最接近的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆