File Exchange

extrema.m, extrema2.m

version 1.0.0.0 (51.6 KB) by
Search all extrema points of a time series or a surface with/without NaN's.

Updated 04 May 2016

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Search all the maxima and minima points (peaks) in a time series (vector) or a surface (matrix), via columns, rows and crossing diagonals, ignoring NaN's elements.
USAGE:

[zmax,imax,zmin,imin]= extrema2(peaks);

where zmax (zmin) are the maxima (minima) elements and imax (imin) their linear index (check IND2SUB).

They come with the examples on the screenshot.

These are the same files as EXTREME.M and EXTREME2.M, but updated.

Cite As

Carlos Adrian Vargas Aguilera (2020). extrema.m, extrema2.m (https://www.mathworks.com/matlabcentral/fileexchange/12275-extrema-m-extrema2-m), MATLAB Central File Exchange. Retrieved .

Georgii Shamuilov

srt10

Pedro Lima

Is there away that we can get the max and min points in order (without being on a increasing or decreasing one)?

Slobodan Cvetkovic

It works for trivial arrays with smooth data values. When I tested with noisy data, I got a lot of misses and bad indices/extrema values. Matlab's function findpeak from Signal Processing toolbox works way better.

HUI-CHUN HUANG

Vic Hu

good.

Abhishek Dasgupta

where is the support for function handle?

SL

It would be great to get an example how you apply `extreme2` on the plot `imagesc(x,y,C)`. - - I can get the frame so I.

Stephanie Liu

excellent tool

Christine Kakalou

Saeed Asghari

Saeed Asghari

K G

I run the function

[hmax,imax,hmin,imin] = extrema2(h)

where h is a 1x15 vector (h=[11717 6172 2963 574 867 1099 1384 1726 2045 2230 2900 3460 3547 1625 617]) and I get the following error:

Attempted to access smaxcol(:,1); index out of bounds because
size(smaxcol)=[0,0].
Error in extrema2 (line 73)
im = unique([smaxcol(:,1);smincol(:,1)]); % Rows with column extrema

Arun Kumar

Found it very useful. Thanks for this submission.

Elsaeed Ali

jghg

Ilya Belevich

Makrim

This one should be added to Matlab native code ... :)

Michael

Does the job of 'findpeaks' with less code, and can find minima with so much less hassle. Might as well be considered a 'required' add-on.

Zohar Bar-Yehuda

Simple and useful.

Phillip

Using this across a broad range of applications, very handy.

Shuangshi

sara

how can I use this mfile to run over my image?

karlosgk

Hugo

Thx, works great!

Vincent

thank you
this saves me a day of coding...

Shirah

Hello, does anybody know how to replicate those detected extrema points onto a grayscale image.

Thank You

Rafael Freire

Do you have an option to put the sensitivity of the peaks? to only get the higher ones....

Kumar

M@lik Ali

Hi all i have to calculate the LUV color components any one can help me...

Camille Couzi

Hola Carlos!
I am having some issues though... I am using your function inside a script which uses fminsearch also... and getting the following error message:

Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can

Error in extrema

Error while evaluating uicontrol Callback

Help! How do I solve this problem!
Gracias y muchos saludos!

raj

[Gmax,imax,Gmin,imin] = extrema2(G);
hold on
plot3(T(imax),f(imax),Gmax,'bo')
for i = 1:length(Gmax)
text(x(imax(i)),y(imax(i)),zmax(i),[' ' num2str(zmax(i))])
end
hold off}
My problem is the T,f,G are of different sizes and an error comes up saying '??? Index exceeds matrix dimensions.' any suggestions please help

raj

I have a problem while using it for an array can u explain an example as u did it for a vector please, I am a begginer with this stuff

Luke Winslow

Luke Winslow

Anusha

Can someone help me on how to adapt this to detect maxima and minima points on an object edge?

Thomas

much better than findpeaks for my data thanks so much!

Onkar Singh Gujral

Aslak Grinsted

Nice. There is also the built-in function findpeaks from the signal processing toolbox:

http://www.mathworks.se/help/toolbox/signal/findpeaks.html

Rafael Freire

Perfect for finds maximun and minimuns in a surface! Great Job

Rick Towler

Nice work.

Rick Towler

Sanjeev

Excellent work

joe saucer

hey guys.. is their anyway for this program to just give me the biggest maxes? my plot has many, many small peaks.. also, can you store these as variables?

Yin Wang

Excellent work, this is exactly what I need.

angeles sierra

kiero agregar un linck a mi fotolog
pero no se como aserle

You are so right Dimitri! I've made a terrible translation from spanish, I meant "extrema points"... Ouch! I need to change even the name!

Dimitri Shvorob

It might be helpful to briefly explain the exact definition of 'extreme points'.

Jacob Eisenstein

Johnny Job

Well done.

Thanks JaeKyu Suhr!, new file with bug fixed in about 1 day...

JaeKyu Suhr

This is excellent, but when i use extreme2.m
There is an error related to a variable "indx".
Therefore, I put a little bit of code in "extreme.m" like this

% NaN's:
inan = find(isnan(x));
if ~isempty(inan)
indx = 1:Nt;
indx(inan) = [];
x(inan) = [];
Nt = length(x);
else
indx = 1:Nt;
%%%%%%%%%%%%%%%%
end

cloves souza

e muito legal

Sasha Trevizo

The author sure had a headache after he finished this, so, thanks for avoid it to me! It works really good!

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux