Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
808 views
in Technique[技术] by (71.8m points)

matlab - Find local maximum value in the vector

Somebody could help me. I use Matlab program.

Suppose, I have vector A,

A = [0 0 1 2 3 5 0 0 0 0 0 2 3 6 7 0 0 0 0 1 1 2 3 4 1]

I would like to get local maximum values and location from the vector A. So, the answer that I would like to get is following.

maxValue = 5, 7 and 4;

maxLocation = 6, 15 and 24;

thank you for your kind.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you have the Signal Processing toolbox then findpeaks should be what you want:

[pks,locs] = findpeaks(A)

For future reference you should know that what you want to find are local maxima. Saying that you want to find the maximum value makes it seem as if you want the global maxima (which would be 7 in this case).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...