How to identify area of a matrix with same values
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix of 10x10 filled with 0s and 1s. There are some areas of 0s enclosed by areas of 1s. I would like to be able to identify specific areas of 0s.
I am using ginput, so I would like to select a 0 from the matrix, and then I want Matlab to identify the area surrounding that specific 0. I believe this can be done with conv2, but I don't know how.
0 commentaires
Réponses (1)
YT
le 19 Oct 2018
This question is similar to this one asked before ( https://mathworks.com/matlabcentral/answers/402080-how-to-find-the-neighbors-of-each-element-in-a-matrix#answer_321522)
So if I understand it corect you want something like this
%small 5x5 example matrix
A = [0 1 0 0 0;
1 1 0 0 0;
0 0 1 1 1;
0 0 1 0 1;
0 0 1 1 1];
%create matrix with zeros with size of A
M = zeros(size(A));
%use the coordinates from ginput; M(row,col)
M(1,1) = 1;
%convolution
C = conv2(M,[1,1,1;1,0,1;1,1,1],'same')>0;
%return indices
[row col] = find(C>0);
%return values (which in your case isnt really interesting cuz will only returns 1's)
A(C)
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!