Get peak values from a Surface mesh figure?
18 views (last 30 days)
Show older comments
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!
6 Comments
Accepted Answer
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
xlabel('x');
ylabel('y');
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');
5 Comments
Scott MacKenzie
on 5 Aug 2021
Edited: Scott MacKenzie
on 5 Aug 2021
@Juan Vences. You're welcome.
BTW, I just simplified the answer. See the new calculations for xx, yy, and zz. Works the same, but much simpler.
More Answers (1)
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: https://www.mathworks.com/help/signal/ref/findpeaks.html
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!