[英]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.