四舍五入到 10 的幂
我有一个变量 tauMax
,我想将其四舍五入到最接近的 10 次方(1、10、100、1000...)。我使用下面的表达式来查找 tau 数组中最接近最大值的整数。我找到最大值是因为我正在尝试计算 10 的幂,这应该是 x 轴的截止值。因此,tauMax 等于 756,因此我想要一个输出 1000 或 3(对于 10^3)的表达式。
tauMax = round(max(tau));
我真的很感激任何帮助!
I have a variable, tauMax
, that I want to round up to the nearest power of ten(1, 10, 100, 1000...). I am using the below expression to find the closest integer to the max value in the tau array. I am finding the max value because I am trying to calculate the power of ten that should be the x axis cutoff. In this cause, tauMax is equal to 756, so I want to have an expression that outputs either 1000, or 3(for 10^3).
tauMax = round(max(tau));
I'd really appreciate any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您正在讨论以 10 为基数,因此您可以使用
log10
来获取位数。怎么样:
Since you're talking base 10, you could just use
log10
to get the number of digits.How about:
我并不真正使用 Matlab,但用我所知道的任何语言执行此操作的通常方法是:取以 10 为底的对数,然后将该数字向上舍入到最接近的整数,然后计算 10 的该数字的幂。在Python中:
I don't really do Matlab, but the usual way to do this in any language I do know is: take the logarithm base 10, then round up that number to the nearest integer, then compute 10 to the power of that number. In Python: