Extract segments of 1's from binary matrix
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Niklas Persson
el 5 de Jul. de 2022
Comentada: Walter Roberson
el 5 de Jul. de 2022
Hi,
I'm looking for a way to extract segments of 1's in a arbirtay big binary matrix. For example, in this matrix:
0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 1
0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 1
I would like to extract 3 segments automatically, for example like:
(2, 1:5)
(2:4, 8)
(3:4, 4) or alternativy (2:4,4)
I'm not bound to the above notation regarding start and stop, it can be stored in any way, it is just an example.
I have played around with find() but I don't seem to be able to get it right
/Niklas
0 comentarios
Respuesta aceptada
Walter Roberson
el 5 de Jul. de 2022
You can bwconncomp and pass in a connection array that is a central row or central column of 1s. You would do that twice, once for each direction, and ignore the components of size 1.
3 comentarios
Walter Roberson
el 5 de Jul. de 2022
To expand a little, bwconncomp accepts connectivity that is a number, but it also accepts connectivity as a mask array such as [0 0 0;1 1 1;0 0 0]
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!