jaffen 发表于 2006-7-24 21:25

【求助】在matlab里面怎么取一个数与之最相近的一个整数?

怎样把小数取之与其最相近的整数?谢谢!

yqing 发表于 2006-7-25 00:44

如果是四舍五入的话,就用round吧。
比如:
>> f=round(0.01)

f =

   0

>> f=round(-0.05)

f =

   0

>> f=round(0.78)

f =

   1

toes 发表于 2006-7-25 10:36

根据不同的需求有好几个呢?在MATLAB帮助中查ROUND看相关链接就行了。

feifeifool 发表于 2006-7-25 10:44

回复 #2 yqing 的帖子

关于Matlab里取整的函数

FLOOR Round towards minus infinity.
FLOOR(X) rounds the elements of X to the nearest integers
towards minus infinity.

ROUND Round towards nearest integer.
ROUND(X) rounds the elements of X to the nearest integers.

CEIL Round towards plus infinity.
CEIL(X) rounds the elements of X to the nearest integers
towards infinity.

FIX Round towards zero.
FIX(X) rounds the elements of X to the nearest integers
towards zero.
页: [1]
查看完整版本: 【求助】在matlab里面怎么取一个数与之最相近的一个整数?