How can I extract not zero numbers from a matrix?

1 次查看(过去 30 天)
I have a matrix, like
M=[0 1 2 5 2 3 0 0 0 0 4 3 2 5 0 0 0 4 3 2 ...];
I'd like to extract n separated matrices, like:
A=[ 1 2 5 2 3];
B=[ 4 3 2 5];
C=[ 4 3 2];
or a matrix n Columns or rows, like
M=[A;B;C]

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2014-6-24
M=[0 1 2 5 2 3 0 0 0 0 4 3 2 5 0 0 0 4 3 2 ];
idx=[0 M~=0 0];
ii1=strfind(idx,[0 1]);
ii2=strfind(idx,[1 0])-1;
out=arrayfun(@(ii,jj) M(ii:jj),ii1,ii2,'un',0);
celldisp(out)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by