How to extract submatrix from the Main matrix???
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
venkat sai
el 31 de Jul. de 2019
Comentada: venkat sai
el 31 de Jul. de 2019
HI everyone!!
I have a matrix 'Z' with values of '1' and '0'. Mat file is attached.
Now i'd like to extract sub matrices from 'Z' which consists of '1' with their corresponding index values .
example:
Z=size(15,10).
From'Z', i should get output like these three matrices in a loop.
a=Z(3:6,2:6);
b=Z(7:9,6:7);
c=Z(8:15,2);
thanks in advance!
0 comentarios
Respuesta aceptada
Guillaume
el 31 de Jul. de 2019
If you have the image processing toolbox:
subnatrices = struct2cell(regionprops(logical(Z), 'Image'))
3 comentarios
Guillaume
el 31 de Jul. de 2019
Have a look at the documentation of regionprops. It can output all sorts of properties. In particular the 'PixelIdxList' (if you want linear indices) or 'PixelList' (if you want 2D indices) will give the indices of the 1s in each submatrix. Or perhaps you want the 'BoundingBox'
submatrices = regionprops(logical(Z), {'Image', 'PixelList', 'PixelIdxList'});
will get you a structure where
- submatrices(i).Image is the ith submatrix
- submatrices(i).PixelList is the 2D list of indices of 1s in the submatrix,
- etc.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!