Automatically selecting peaks from a surf plot an creating new variables for them

2 次查看(过去 30 天)
Hello
I have a 100x100 numeric variable, which looks like this when plotted on a surf plot:
What I'm looking for, is a way to automatically create some new variables, each containing only one of the peaks, with the rest of the values deleted, as shown below :
Ideally I would like this to work for any number of peaks (generating one new variable for each of them),
and if possible, ignoring peaks below a certain threshold would be nice.
Thank you for your time!

回答(1 个)

Prateekshya
Prateekshya 2023-11-7
编辑:Prateekshya 2023-11-7
Hi Aristarchos,
As per my understanding, you want to extract the peak values from a 3D surface plot.
The closest workaround is to find the maximum values in the data from which the figure is generated. You can use the following functions.
[maxValue, maxIndex] = max(Z(:)); % Gives the maximum value and the corresponding index
[row, col] = ind2sub(size(Z), maxIndex); % Gives the row and column for the position
[row, col] = find(Z > threshold); % Gives the rows and columns for the corresponding positions
peakValues = Z(sub2ind(size(Z), row, col)); % Gives the exact values
binaryImage = imregionalmax(Z); % Gives a matrix indicating 1 at the positions of maximum values
[row, col] = find(binaryImage); % Gives the set of rows and columns for the corresponding positions
peakValues = Z(sub2ind(size(Z), row, col)); % Gives the exact values
"Z" is the matrix containing the surface data.
If you only have the figure and not the data, you can follow this to extract the data from the figure: https://in.mathworks.com/matlabcentral/answers/100687-how-do-i-extract-data-from-matlab-figures
I hope it helps!
  1 个评论
Aristarchos Mavridis
Hello Prateekshya,
Thank you for taking the time to answer.
I'm familiar with finding local maxima, my problem is more about selecting the whole "mountain" around them automatically. I know there are some gradient ascent methods I could use, but I was wondering whether matlab has a built-in tool that could do the job.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by