Matlab中的取整函数fix, floor, ceil与round
来源:互联网 发布:频无损剪切软件 编辑:程序博客网 时间:2024/04/29 01:46
1. fix 向0取整
fix([-0.5 -0.4 0.4 0.5]) ==> [0 0 0 0]
2. floor 向-inf取整
floor([-0.5 -0.4 0.4 0.5]) ==> [- 1 -1 0 0]
3. ceil 向+inf取整
ceil([-0.5 -0.4 0.4 0.5]) ==> [0 0 1 1]
4. round 四舍五入
round([-0.5 -0.4 0.4 0.5]) ==> [-1 0 0 1]
最开始用matlab时,程序中涉及到取整,因为使用C, C++等其他编程语言的原因,首先想到的是直接强制转换,使用int32(),结果如下,令我有点吃惊,居然和round效果一样,四舍五入。
int32([-0.5 -0.4 0.4 0.5]) ==> [-1 0 0 1]% 注意数据类型double已变为int32
但在C, C++中,int取整是向0取整,与matlab中的fix()效果一样,测试代码如下:
int main(){double data[] = {-1.5, -0.5, -0.4, 0.4, 0.5, 1.5};for (size_t i=0; i<6; ++i)cout << int(data[i]) << "\t" << (int)data[i] << endl;getchar();return 0;}
输出结果:
-1 -10 00 00 00 01 1
故写这篇文章记录下,供自己及他人查阅,欢迎讨论。
- Matlab中的取整函数fix, floor, ceil与round
- matlab中的取整函数,round,fix,floor,ceil
- Matlab取整函数(fix, floor, ceil, round)的使用
- MATLAB取整函数:fix, floor, ceil, round
- matlab 取整函数 fix floor ceil round
- Matlab取整函数 fix, floor, ceil, round的区别
- matlab 关于取整函数 fix, floor, ceil, round
- matlab中的round、ceil、floor、fix函数
- 取整函数(fix, floor, ceil, round)
- matlab中的fix,round,floor,ceil的区别与涵义
- matlab中的fix,round,floor,ceil的区别与涵义
- matlab中fix, floor, ceil, round 函数
- MATLAB的取整函数:fix(x), floor(x) ,ceil(x) , round(x)
- matlab之any()、imshow()、image()、imagesc()、取整函数fix, floor, ceil,round
- C/C++取整函数ceil(),floor() fix round
- matalb取整函数round、fix、ceil和floor函数在fpga中的实现
- Matlab里四个函数:Floor, Ceil, Fix, Round
- Matlab里面的四个函数:Floor, Ceil, Fix, Round
- Source Insight 显示全路径
- 使用JDK的keytool来为Tomcat配置SSL认证(一)
- CALayer实现,界限、透明度、位置、旋转、缩放组合动画
- Android开发之XML文件解析
- File not found: MaskProp.dcu
- Matlab中的取整函数fix, floor, ceil与round
- Wikioi P1026 逃跑的拉尔夫
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- 关于malloc申请内存
- cmd下运行java程序
- VS2010 安装 Boost 库 1.54
- <link href ="css/index.css" rel="Stylesheet" type="text/css" />
- 一句话总结Windbg 32位版本和64位版本的选择
- IOS成长之路-实现界面切换和数据的传递