声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 5326|回复: 3

[编程技巧] 【求助】在matlab里面怎么取一个数与之最相近的一个整数?

[复制链接]
发表于 2006-7-24 21:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
怎样把小数取之与其最相近的整数?谢谢!
回复
分享到:

使用道具 举报

发表于 2006-7-25 00:44 | 显示全部楼层
如果是四舍五入的话,就用round吧。
比如:
>> f=round(0.01)

f =

     0

>> f=round(-0.05)

f =

     0

>> f=round(0.78)

f =

     1
发表于 2006-7-25 10:36 | 显示全部楼层
根据不同的需求有好几个呢?在MATLAB帮助中查ROUND看相关链接就行了。
发表于 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

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-4 21:04 , Processed in 0.090582 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表