フィルターのクリア

How to find the descending index in each row of a matrix?

1 回表示 (過去 30 日間)
Marmar
Marmar 2018 年 2 月 26 日
コメント済み: Marmar 2018 年 2 月 26 日
Hi there, I have data for about 2000 lakes through 11 days so I have a 2000x11 matrix. which I want to know for each lake (row) when the numbers become descending. Lets say my matrix is A ( it shows the first four rows of my matrix) and A is:
[26 26 25 25 25 25 25 25 25 6 3;
558 558 558 558 533 521 494 367 367 64 8;
214 212 210 210 182 156 106 73 73 41 9;
448 448 445 445 375 219 132 130 130 73 32]
Finally I want an index vector (2000x1) that shows me the index of the descending point for each row. Means I want my result for the example matrix A to be like matrix below:
3
5
2
3
Any idea is really appreciated.
  3 件のコメント
jonas
jonas 2018 年 2 月 26 日
編集済み: jonas 2018 年 2 月 26 日
Not the most elegant solution but it gets the job done:
[nrow ncol]=size(A)
B=diff(A');
[row col]=find(B<0)
for i=1:nrow
ind(i)=row(min(find(col==i)))+1
end
Marmar
Marmar 2018 年 2 月 26 日
This solution works as well. Thank you.

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

採用された回答

James Tursa
James Tursa 2018 年 2 月 26 日
E.g., assuming there is always a decrease:
[~,x] = max(diff(A,1,2)<0,[],2);
result = x + 1;
If there is not a decrease, what would you want the code to produce?
  2 件のコメント
Marmar
Marmar 2018 年 2 月 26 日
I want 1 for those row, but there is always a decrease.
Marmar
Marmar 2018 年 2 月 26 日
That works well. Thank you so much.

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

その他の回答 (0 件)

カテゴリ

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