eliminate zero elements and separate into different matrix

if i have a matrix like [0 0 0 0 1 2 3 0 0 3 2 0 0 0 3 4 4 5 0],how can I get three matrix [1 2 3];[3 2] and [3 4 4 5].

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 17 日

0 投票

A=[0 0 0 0 1 2 3 0 0 3 2 0 0 0 3 4 4 5 0]
idx=A~=0
ii1=strfind([0 idx],[0 1])
ii2=strfind([idx 0],[1 0])
out=arrayfun(@(x,y) A(x:y),ii1,ii2,'un',0)
celldisp(out)

3 件のコメント

weifeng wang
weifeng wang 2016 年 7 月 17 日
thank you for your answer,can I use this method to processing a 74270x1 matrix, shown below
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 17 日
You can do it with any array supported by Matlab, but your figure doesn't show a matrix!
weifeng wang
weifeng wang 2016 年 7 月 17 日
Thank you very much!!! It perfectly works, awesome!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by