eliminate zero elements and separate into different matrix
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
weifeng wang
am 17 Jul. 2016
Kommentiert: weifeng wang
am 17 Jul. 2016
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].
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 17 Jul. 2016
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 Kommentare
Azzi Abdelmalek
am 17 Jul. 2016
You can do it with any array supported by Matlab, but your figure doesn't show a matrix!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
