extract non-zeros block from matrice

I have a matrix that contains several non-zeros blocks.The rest of the elements are zero. I want to put each of these blocks in a separate matrix. how can i do it?

Antworten (1)

jonas
jonas am 26 Feb. 2018

0 Stimmen

Not sure exactly what you want to do. The following creates a vector B containing all non-zeros of A
B=A(A~=0)
Do you want to extract several small matrices from a larger global matrix?

5 Kommentare

khatere darvish
khatere darvish am 26 Feb. 2018
dear jonas yes,i want to extract small matrices from a largger global matrix. for example i want to extract the small matrices are shown in the figure
khatere darvish
khatere darvish am 26 Feb. 2018
jonas
jonas am 26 Feb. 2018
Bearbeitet: jonas am 26 Feb. 2018
If you already know the indices of your blocks, then you can simply extract them by:
a1=A(row1:row2,col1:col2);
In your example: a1=A(1:2,1:3); a2=A(1:3,6:7);
Or do you need a more general function for extracting any rectangular-sized block?
EDIT: The image processing toolbox has a function called bwconncomp() that will find connecting non-zero values (BLOCKS) and output their indices. It should work as long as the blocks are completely separated by zeros.
Jan
Jan am 26 Feb. 2018
Do you have the image processing toolbox?
khatere darvish
khatere darvish am 27 Feb. 2018
yes i have it. thank you so much for your help

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Gefragt:

am 26 Feb. 2018

Kommentiert:

am 27 Feb. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by