How to find peaks in 3d mesh?

209 views (last 30 days)
OldCar on 6 Apr 2016
Hi, I have a mesh made from data ([Y,X] matrix and Z values) and I would like to find the peaks and report their position. How can I do it?

Accepted Answer

Mike Garrity
Mike Garrity on 6 Apr 2016
Edited: Mike Garrity on 6 Apr 2016
If your X & Y are monotone, and you have the Image Processing Toolbox, then the imregionalmax function is pretty robust. It handles all of the special cases like flat regions.
[x,y] = meshgrid(linspace(-3,3,10));
z = 10*ones(10,10);
z(2:4,2:4) = 22;
z(6:8,6:8) = 33;
z(2,7) = 44;
z(3,8) = 45;
z(4,9) = 44
ix = find(imregionalmax(z));
hold on
Chibuzo Nnonyelu
Chibuzo Nnonyelu on 13 Dec 2018
You need to use the meshed X and Y. As in, fetched your ix indices from the meshed X and Y.

Sign in to comment.

More Answers (2)

donghun lee
donghun lee on 3 Jul 2018
Same Error :)

Cristian Alistarh
Cristian Alistarh on 17 Jun 2020
Edited: Cristian Alistarh on 17 Jun 2020
I think you got this error:
Index exceeds the number of array elements
As stated above, you need to use the meshed X and Y.
Digging further into this, the indicies of the output of the imregionalmax function is given in linear array indicies and not 2D (row, columns) as one would normally expect. I had the same problem and another way to solve this is to use the convert linear indices to subscripts function ind2sub
ix = find(imregionalmax(z));
[a,b] = ind2sub(size(z),ix);
I am not sure if it will give you 100% what you are looking for, but explains the previous behaviour and another way on how to fix it.
Cristian Alistarh
Cristian Alistarh on 7 Jul 2020
OK, sounds better than my suggestion.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by