How to extract submatrix from the Main matrix???
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Guillaume
il 31 Lug 2019
If you have the image processing toolbox:
subnatrices = struct2cell(regionprops(logical(Z), 'Image'))
3 Commenti
Guillaume
il 31 Lug 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!