Get peak values from a Surface mesh figure?

4 views (last 30 days)
Hello dear Matlab users !
Question for those who have lots of Matlab skills (i don't '^_^ ) and love to give some help
Let's say there is a figure (surface mesh) which plots a surface from 3 equal size matrices ("m" by "n"). And from that figure, peak values are of interest. Could somebody share an idea of how to get those peak values (x,y,z) without looking/searching for them manually please? (could be using the "Brush" [preferably], or a "fancy function"?... I have no Image Processing Toolbox too... i think lol)
Please look at attached image for example
Many thanks!

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 4 Aug 2021
Edited: Scott MacKenzie on 5 Aug 2021
Here's a solution that does not use findpeaks (since you do not have the Signal Processing Toolbox). Below, I am using MATLAB's build-in peaks function and a threshold of 6. In the surface plot you posted, the peaks circled are above about 156.5, so you'll need to adjust the variable threshold accordingly.
% test data
[X,Y,Z] = peaks(25);
mesh(X,Y,Z); % can also use surf
hold on;
threshold = 6; % find peaks with Z above this value (adjust, as needed)
peakLogical = Z > threshold;
xx = X(peakLogical);
yy = Y(peakLogical);
zz = Z(peakLogical);
vOffset = 0.5; % shift up a bit so points are clearly visible
zz = zz + vOffset;
% show peaks in surface plot
scatter3(xx, yy, zz, 'r', 'filled');
Juan Vences
Juan Vences on 5 Aug 2021
@Scott MacKenzie Thanks so much for all of your time and great help
Super thumbs up!
(in my case I removed "[X,Y,Z] = peaks(25);" in my script (yours actually). For the rest of the script, I used my 'data matrices' and it worked, though I'm not too sure how by removing that 'part/line' it affects the On the plot generated with my data, I can see the dots on the peaks (depending on the thresold defined of course), and coordinates match and make sense, so I guess it works!)

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 4 Aug 2021
You can use MATLAB's built in findpeaks() fcn to clocate local maxima of your data - see the doc:




Community Treasure Hunt

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

Start Hunting!

Translated by