Peak-finding function doesn't work.

1 回表示 (過去 30 日間)
Jan
Jan 2011 年 3 月 30 日
function [M] = peak(A)
for j=2:size(A,2)
if A(j,2)-A(j-1,2) >= 0 && A(j,2)-A(j+1,2) >= 0
M=[M,A(j,1)];
end
end
This is supposed to be a function that makes a vector M that contains all local peaks from a vector A. It doesn't do anything. Could anyone tell me what is wrong?
Greetings and thanks in advance

採用された回答

Matt Fig
Matt Fig 2011 年 3 月 30 日
What do you mean by, "Doesn't do anything?" Do you mean you get an error? I would imagine that the error is something about an undefined variable M. If you are going to do it this way, you should define M before the loop.
M = [];
  2 件のコメント
Jan
Jan 2011 年 3 月 30 日
I did that the first time, added it again and now it works. Very strange...
Matt Fig
Matt Fig 2011 年 3 月 30 日
Does this mean that you accept the answer? Please indicate this by pushing the appropriate button.

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

その他の回答 (0 件)

カテゴリ

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