How to find peaks in matrix the rest are 0

조회 수: 1 (최근 30일)
pzaksek
pzaksek 2022년 6월 10일
댓글: pzaksek 2022년 6월 11일
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일
Your speed, help, kindness, ... is amazing and fantastic.
THANK YOU!!!!!!!!!!
Dyuman Joshi
Dyuman Joshi 2022년 6월 10일
You are welcome!!!

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

추가 답변 (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.
pzaksek
pzaksek 2022년 6월 11일
Thank you very much, you are very kind.

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

카테고리

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