Get peak values from a Surface mesh figure?

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 comentarios

Scott MacKenzie
Scott MacKenzie el 4 de Ag. de 2021
You can use findpeaks. See THIS ANSWER for an example with surface data.
Juan Vences
Juan Vences el 4 de Ag. de 2021
Hi Scott, thank you for your answer
Matlab says it requires "Signal Processing Toolbox" ... i think i don't that one '^_^
Scott MacKenzie
Scott MacKenzie el 4 de Ag. de 2021
Hmm, OK, well then perhaps post your data.
Juan Vences
Juan Vences el 4 de Ag. de 2021
yeahh... that would be very difficult to do in here...
Thanks for the suggestion though!
Scott MacKenzie
Scott MacKenzie el 4 de Ag. de 2021
OK, I'll post a solution in a moment that does not use findpeaks.
Juan Vences
Juan Vences el 4 de Ag. de 2021
Appreciate your help!

Iniciar sesión para comentar.

 Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 4 de Ag. de 2021
Editada: Scott MacKenzie el 5 de Ag. de 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 comentarios

Juan Vences
Juan Vences el 4 de Ag. de 2021
Ohhhh! I'm testing it right now
(quick question, what the "(25)" is for? I can't figure it out from the documentation..sorry '^_^)
Scott MacKenzie
Scott MacKenzie el 4 de Ag. de 2021
The "25" is just the size of the test data set that the peaks function creates (i.e., 25x25). Your dataset will obviously be much larger.
Juan Vences
Juan Vences el 4 de Ag. de 2021
It works, just got to do some adjustments but I think this is good!
Scott MacKenzie
Scott MacKenzie el 5 de Ag. de 2021
Editada: Scott MacKenzie el 5 de Ag. de 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.
Juan Vences
Juan Vences el 5 de Ag. de 2021
Editada: Juan Vences el 5 de Ag. de 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 results...lol. 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!)

Iniciar sesión para comentar.

Más respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 4 de Ag. de 2021

0 votos

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

Productos

Versión

R2021a

Preguntada:

el 4 de Ag. de 2021

Editada:

el 5 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by