finding prominent maxima and minima of a column vector
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    az
 el 21 de Jun. de 2019
  
    
    
    
    
    Comentada: Star Strider
      
      
 el 23 de Jun. de 2019
            Hello,
Suppose I Have a column vector wcich has multiple maxima and minima, I just want to find  the index  of N= 4 number of them ( prominent maxia and minima). 
And if I use something like 'findpeak' then it gives a lots of local max and min as for a noisy signal. I want to get the prominant max & min indices of the 2nd colm of the attachment please. 
Thank you
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 21 de Jun. de 2019
        Although findpeaks needs some help here, it can find all four: 
[D,S] = xlsread('ab1.xlsx');
[pks,plocs] = findpeaks([D(:,2); min(D(:,2))], 'MinPeakProminence',1);   % Append ‘0’ To Far End To Identify Last Peak
[vls,vlocs] = findpeaks(-D(:,2), 'MinPeakProminence',1)
figure
plot(D(:,1), D(:,2))
hold on
plot(D(plocs,1), pks, '^r')
plot(D(vlocs,1), vls, 'vr')
hold off
grid
legend('Data','Peaks','Valleys')
The associated times are: D(plocs,1).  
pks =
    1.2000
    1.2001
    1.2001
    1.2000
locs =
        3165
        4072
        4675
        5138
Similarly for the valleys: 
vls =
   1.0e-04 *
   -0.0140
    0.3678
    0.5941
   -0.1694
vlocs =
        2708
        3753
        4446
        4954
2 comentarios
  Star Strider
      
      
 el 21 de Jun. de 2019
				As always, my pleasure.  
We need ‘S’ so I know what the columns represent.  (More knowledge is generally better.)  There is no absolute guarantee that the first column is time.  You mentioned a column vector, not the second column of an (Nx2) matrix, so I had to be sure I knew what I was working with.  
The findpeaks function does not consider the end of a vector to be a peak, so it will never return that as a peak.  Concatenating that vector with the minimum of the vector creates a peak (as far as findpeaks knows) where one did not previously exist.  Since you stated that there were four peaks, and the last one looked like the first three (as much as we can see of it, anyway), I made it a peak by defining a lower value after it.  (I do not generally recommend creating data where none previously existed, however here it seemes safe in order to define the last peak.)  
Más respuestas (1)
  az
 el 21 de Jun. de 2019
        9 comentarios
  Star Strider
      
      
 el 23 de Jun. de 2019
				As always, my pleasure.  
‘So in capacity3.m I omit those data points  manually from line 19th to 26.’  
There are several way to do this, one is to completely eliminate them by setting that range equal to the empty array [], another is to set them equal to NaN.  What you do depends on the result you want.  
I ran your code, and it seems to do what you want.  There are several connecting lines that appear strange to me (they do not appear on the plots my code produces), however looking at your plot calls, you added them specifically, so they are not artefacts.  
I do not understand what you want to do, especially with respect to adding more for loops.  I encourage you to experiment to get your code to do what you want it to.  
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!