How to find peaks in matrix the rest are 0

1 view (last 30 days)
Hello
Im asking for help. It's more complicated than I know about matlab ...
for clarification and explanation I use excel....
I have a data matrix (see picture). I would like to find different peakses. Other values becomes 0 (see picture 2).
thank you so much for the help
Peter
  1 Comment
Dyuman Joshi
Dyuman Joshi on 10 Jun 2022
Please show proper data, without blue bubbles. Show the whole input data and the corresponding output data.

Sign in to comment.

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 10 Jun 2022
Run a double for loop through all the elements
A = randi(50,7,11) %sample matrix
A = 7×11
31 11 34 5 45 26 34 50 40 30 43 25 42 25 48 46 25 42 1 27 15 25 30 3 1 10 22 34 47 13 17 44 4 15 11 17 34 23 36 44 36 46 1 33 37 43 16 38 45 46 4 1 4 9 30 29 25 26 20 19 48 8 10 37 47 6 1 36 39 16 48 45 45 33 26 31 8
B=zeros(size(A));
for i=1:size(A,1)
for j=1:size(A,2)
M = zeros(size(A));
M(i,j) = 1;
if all(A(i,j)>A(conv2(M,[1,1,1;1,0,1;1,1,1],'same')>0)) %checking if A(i,j) is local maxima
B(i,j)=A(i,j);
end
end
end
B
B = 7×11
0 0 0 0 0 0 0 50 0 0 43 0 42 0 48 0 0 0 0 0 0 0 0 0 0 0 0 0 47 0 0 0 0 0 0 0 0 0 0 0 0 46 0 0 0 43 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 0 0 0 39 0 0 0 0 0 0 0 0
  2 Comments
pzaksek
pzaksek on 10 Jun 2022
Your speed, help, kindness, ... is amazing and fantastic.
THANK YOU!!!!!!!!!!

Sign in to comment.

More Answers (2)

pzaksek
pzaksek on 10 Jun 2022
Edited: pzaksek on 10 Jun 2022
My intention is to show that i would like to peaks (...Matrixes are dimensons 100x 200
I don't know how many peaks are there? How big they are ? I don’t know their position in the matrix?
the code should derivate adjacent places so long that only 1 number for each peak remains. the surrounding towns are 0s.

pzaksek
pzaksek on 11 Jun 2022
hello, you helped me a lot :)
But I would ask for more help.
From the dataset, I can draw the areas (imshow (sitesMat2, [])) where the events took place. I have to find the highs (maximum) in this area. Areas are changing inside the matrix ... This picture and database is simple. Later, there are many more of these areas. I added a database. You can also draw a 3D image that will answer certain questions about the complexity of the problem.
Is there a way or option for matte code to look for maxima in these circles, which vary in size depending on the location ...Must find only one maximum :)The above code is great, but it finds me multiple maxima in the same area.
I’ve added pictures for areas where I need to find highs(maximums).
thank you all in advance
  2 Comments
Dyuman Joshi
Dyuman Joshi on 11 Jun 2022
Please ask this as another question. (MATLAB Answers etiquette) In that way, others can also help you incase I can't.
pzaksek
pzaksek on 11 Jun 2022
Thank you very much, you are very kind.

Sign in to comment.

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!