Finding the location of maximum peaks in a plot wi

2020-02-16 05:20发布

问题:

Suppose I have the F matrix like this:

F =
0, 0, 106, 10, 14, 20, 20, 23, 27, 26, 28, 28, 28, 23
       |                        |           |
     peak                     peak         peak 

I'm using the command plot(F). I want to get the indexes of the peaks in the data.

This is the code I have so far, it does not work:

[max_x,index_x]=max(x);
e=index_x;
for i=1:11
    index_x(i)=e;
    e=e+16;
end

Is there a builtin function in matlab that will do this for me?

回答1:

Use the findpeaks function (Signal Processing Toolbox).

[peakVal,peakLoc]= findpeaks(x);


回答2:

Well here is what I prefer:

[maxval maxloc] = max(A(:));