フィルターのクリア

Help me find the index value for first minimum value in a matrix.

9 ビュー (過去 30 日間)
Divya Ganesan
Divya Ganesan 2021 年 3 月 29 日
編集済み: Walter Roberson 2021 年 4 月 21 日
I have a matrix
A=[ 34 67 78 88 4 15 23 67 78 56 3 2 24 67]
First minimum value in this matrix is 4. (this is first drop). Index of 4 is 5.
After 4 many minimum value is there (i.e) 2.
I don't want to consider the other minimum value 2.
I want index of first minimum value (i.e first drop) as a output...
output =( first minimum value 4 and its index is 5)
someone please suggest me a code to solve this..

採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 29 日
A=[ 34 67 78 88 4 15 23 67 78 56 3 2 24 67]
A = 1×14
34 67 78 88 4 15 23 67 78 56 3 2 24 67
find(diff(A) < 0, 1)
ans = 4

その他の回答 (2 件)

Bruno Luong
Bruno Luong 2021 年 3 月 29 日
[~,idx] = min(A)
  5 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 29 日
OP stands for "Original Poster"
Bruno Luong
Bruno Luong 2021 年 3 月 29 日
Not sure your definition of "first drop", but try this
d=diff(A);
find(d(1:end-1)<=0 & d(2:end)>=0,1,'first')+1

サインインしてコメントする。


Riley
Riley 2021 年 3 月 29 日
編集済み: Riley 2021 年 3 月 29 日
A=[ 34 67 78 88 4 15 23 67 78 56 3 2 24 67];
flag=0;
for i=1:length(A)-1
if flag==0&&A(i+1)<A(i)
flag=1;
continue;
end
if flag==1&&A(i)<A(i+1)
first_min=A(i);
idx=i;
break;
else
flag=0;
end
end
first_min
idx
Hi, OP means original poster which is you here. The code above can find the first minimum value and its indice, only if 4 is the first drop. As you can see, if the number ahead of 4 is smaller than 88, this code fails. This is not the perfect solution. Hope you can find a better one.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by