Borrar filtros
Borrar filtros

How to identify area of a matrix with same values

3 visualizaciones (últimos 30 días)
Mollymomo
Mollymomo el 19 de Oct. de 2018
Respondida: YT el 19 de Oct. de 2018
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.

Respuestas (1)

YT
YT el 19 de Oct. de 2018
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)

Categorías

Más información sobre Visual Exploration en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by