Borrar filtros
Borrar filtros

eliminating isolated areas in a matrix

1 visualización (últimos 30 días)
Andrew Luce
Andrew Luce el 20 de Abr. de 2022
Editada: Matt J el 20 de Abr. de 2022
I have four 4x4 matrices that I want to concatinate together to make 1 8x8 that will contain 1's and 0's. How can I check to see if when I combine the 4 together that I do not create areas that are "isolated". In other words sections of 1's that are not connected to the rest of the 1's. Connecitons would be if a 1 has another 1 above, below, to the right or to the left.
I can some challenge with the edges of the matrix and if there are any peninusla type regions.
thank you
Andrew
1 1 0 0 1 1 1 1 %failure due to island formed here % Both of these should be able to pass (i just rotated some of the sections)
1 0 0 1 0 1 1 1 1 1 0 0 1 1 1 1 <-- 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1
1 1 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 0 1 1
1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1
--> 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 0 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1

Respuestas (1)

Matt J
Matt J el 20 de Abr. de 2022
Editada: Matt J el 20 de Abr. de 2022
How can I check to see if when I combine the 4 together that I do not create areas that are "isolated"
Use bwconncomp to count the number of connected regions. If they are greater than 1, you know you will have created what you don't want.
BW=[1 1 0 0 1 1 1 1
1 0 0 1 0 1 1 1
1 1 1 1 0 0 1 0
1 1 1 1 0 0 0 0
0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1];
CC=bwconncomp(BW,4);
failure = (CC.NumObjects>1)
failure = logical
1

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by