MATLAB Answers

Get peak values from a Surface mesh figure?

조회 수: 4(최근 30일)
Juan Vences
Juan Vences 2021년 8월 4일
편집: Juan Vences 2021년 8월 5일
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
Juan Vences
Juan Vences 2021년 8월 4일
Appreciate your help!

댓글을 달려면 로그인하십시오.

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 8월 4일
편집: Scott MacKenzie 2021년 8월 5일
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');
  댓글 수: 5
Juan Vences
Juan Vences 2021년 8월 5일
@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!)

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 8월 4일
You can use MATLAB's built in findpeaks() fcn to clocate local maxima of your data - see the doc:
  댓글 수: 1
Juan Vences
Juan Vences 2021년 8월 4일
I'm exploring that option

댓글을 달려면 로그인하십시오.




Community Treasure Hunt

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

Start Hunting!

Translated by