简体   繁体   English

如何在matlab中找到最小和最大浮点数

[英]how to find min and max of float number in matlab

The min and max functions in MATLAB work on only integer values. MATLAB中的minmax函数仅适用于整数值。 How can I find the min and max of a double vector? 如何找到双精度矢量的最小值最大值

a = [2.1 3.4 5.6 7.6]
min(a)

returns to me: 回到我身边:

Subscript indices must either be real positive integers or logicals.

You've assigned min as a variable name for an array somewhere in your code. 您已在代码中的某处为数组分配了min作为变量名。

When you call min(a) , MATLAB is trying to grab the indices [2.1,3.4,5.6,7.6] from your array min . 当您调用min(a) ,MATLAB试图从数组min获取索引[2.1,3.4,5.6,7.6] To fix this problem, simply call the variable something else. 要解决此问题,只需将变量命名为其他变量即可。

EDIT: And if you're running it outside of a function, clear min and max , as @Acorbe points out. 编辑:并且,如果您正在函数外部运行它,请清除minmax ,如@Acorbe所指出的。

You need to clear min and max since they are assigned already and their variable counterparts hide the function names. 您需要清除minmax因为它们已经被分配,并且它们的变量对应变量隐藏了函数名。

To use them as functions, do first 要将它们用作功能,请先执行

 clear min
 clear max

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM