MATLAB中的取整函数(fix、round、floor、ceil)
- fix - 向零方向取整
fix Round towards zero.
fix(X) rounds the elements of X to the nearest integers towards zero.
例:
t =
7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590
fix(t)
ans =
7 3 3
2 3 7
5 2 7
- round - 向最近的方向取整,亦即“四舍五入”
round rounds towards nearest decimal or integer
round(X) rounds each element of X to the nearest integer.
例:
t =
7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590
round(t)
ans =
8 4 4
2 3 7
6 3 7
- floor - 向负无穷大方向取整
floor Round towards minus infinity.
floor(X) rounds the elements of X to the nearest integers towards minus infinity.
例:
t =
7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590
floor(t)
ans =
7 3 3
2 3 7
5 2 7
- ceil - 向正无穷大方向取整
ceil Round towards plus infinity.
ceil(X) rounds the elements of X to the nearest integers towards infinity.
t =
7.6806 3.5388 3.6130
2.3309 3.4719 7.4163
5.8736 2.5372 7.0590
ceil(t)
ans =
8 4 4
3 4 8
6 3 8
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Brainfly: 用 C# 类型系统构建 Brainfuck 编译器
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· DeepSeek 全面指南,95% 的人都不知道的9个技巧(建议收藏)
· 对比使用DeepSeek与文新一言,了解DeepSeek的关键技术论文
· Brainfly: 用 C# 类型系统构建 Brainfuck 编译器
· DeepSeekV3+Roo Code,智能编码好助手
· AI编程:如何编写提示词