Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
752 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 Reply

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...