截断变量MATLAB [英] Truncating variable MATLAB

查看:156
本文介绍了截断变量MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MATLAB中的数组A.此数组中的值最多包含5个小数.我想将这些值截断为更少的十进制数.

I'm working with an array A in MATLAB. The values in this array have up to 5 decimals. I would like to truncate those values to a less number of decimal.

有没有办法做到这一点?

Is there a way to accomplish this?

谢谢!

推荐答案

由于某种原因,Matlab的"truncate"函数称为fix.所以

For some reason, Matlab's "truncate" function is called fix. So

>> fix(3.5) 
ans = 3

>> fix(-3.5)
ans = -3

要将任何内容截断,舍入,舍入或舍入到小数位数,请乘以数十次幂,截断,舍入,舍入或舍入到ceil,然后将结果除以数十次幂.

To truncate, round, floor, or ceil anything to a given number of decimals, multiply by powers of tens, truncate, round, floor, or ceil, and then divide the result by powers of tens.

所以:

>> fix(123.456 * 10^2)
ans = 12345

>> ans / 10^2
ans = 123.45

这篇关于截断变量MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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