How to find peaks in matrix the rest are 0

2 次查看(过去 30 天)
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 个评论
Dyuman Joshi
Dyuman Joshi 2022-6-10
Please show proper data, without blue bubbles. Show the whole input data and the corresponding output data.

请先登录,再进行评论。

采纳的回答

Dyuman Joshi
Dyuman Joshi 2022-6-10
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 个)

pzaksek
pzaksek 2022-6-10
编辑:pzaksek 2022-6-10
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 2022-6-11
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 个评论
Dyuman Joshi
Dyuman Joshi 2022-6-11
Please ask this as another question. (MATLAB Answers etiquette) In that way, others can also help you incase I can't.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by