eliminate zero elements and separate into different matrix

조회 수: 13 (최근 30일)
weifeng wang
weifeng wang 2016년 7월 17일
댓글: weifeng wang 2016년 7월 17일
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일
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
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개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by