[英]How to find out consecutive sequence of numbers in two different vectors in MATLAB?
[英]How to find the min value of a sequence of negative numbers?
我有一个像这样的负值向量:
values = [-15, -6.45, -3.75, -5.55, -2.40]
我想知道其中哪个是最小的以及相应的索引。 我尝试使用min
函数,但是遇到了这个错误:
Subscript indices must either be real positive integers or logicals.
我该如何解决这个烦人的问题?
我认为您正在尝试使用min
的直接输出来访问数组中的条目。 min
的返回值是实际最小值,而不是数组中的索引。
要获取值和索引,请尝试使用以下代码:
values = [-15, -6.45, -3.75, -5.55, -2.40];
[minval,minindex] = min(values)
这将返回minval = -15
和minindex = 1
。 使用minindex
您可以寻址数组中的条目。 例如,在values
-array中:
values(minindex)
这将返回课程-15
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.