How can i get the last element of a maxium with the help of findpeaks?

1 回表示 (過去 30 日間)
Denis Paul
Denis Paul 2020 年 8 月 6 日
コメント済み: Denis Paul 2020 年 8 月 6 日
Hello,
i want to find a maximum with the last element. I want to use findpeaks instead of islocalmax to solve my problem.
So my question is how can i get the last element of a maxium with the help of findpeaks?
Example with findpeaks:
data = [25 8 15 5 6 10 10 10 1 20 7];
x = 1:1:11;
[pks,pksInx] = findpeaks(data);
figure
plot(x,data,'b')
hold on
plot(pksInx,pks,'ko')
hold off
But how it should looks like with islocalmax:
TF1 = islocalmax(data, 'FlatSelection', 'last');
figure
plot(x,data,'b',x(TF1),data(TF1),'ko')
  2 件のコメント
madhan ravi
madhan ravi 2020 年 8 月 6 日
Why not islocalmax() any reasons?
Denis Paul
Denis Paul 2020 年 8 月 6 日
No, there is not a big reason. I was just interested because its possible with the islocalmax() function and maybe its was possible with the findpeaks() function also. Now i know it isn't.

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

採用された回答

madhan ravi
madhan ravi 2020 年 8 月 6 日
It states:
“For the flat peak, the function returns only the point with lowest index.”
  1 件のコメント
Denis Paul
Denis Paul 2020 年 8 月 6 日
OK, so i must use islocalmax(). Thanks for the explanation.

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

その他の回答 (1 件)

Mario Malic
Mario Malic 2020 年 8 月 6 日
According to documentation, variable you named pks is a vector that contains values you need. You just need to call the last element of the vector.
pks(end)
  2 件のコメント
madhan ravi
madhan ravi 2020 年 8 月 6 日
That would just select the last peak. According to what I understood OP wants the last peak if they are the same peaks. Three 10s and OP wants the last 10 instead of the first.
Mario Malic
Mario Malic 2020 年 8 月 6 日
Ah true.

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

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by