How to split array based condition

Suppose I have an array like this A = [0 1 0 2 3 0]. How can i get A1 = [1] and A2 = [2 3] based their position between 0.

답변 (1개)

KSSV
KSSV 2018년 5월 30일
편집: KSSV 2018년 5월 30일

0 개 추천

A = [0 1 0 2 3 0] ;
ii = zeros(size(A));
jj = A > 0;
ii(strfind([0,jj(:)'],[0 1])) = 1;
idx = cumsum(ii).*jj;
iwant = accumarray( idx(jj)',A(jj)',[],@(x){x'})

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2018년 5월 30일

편집:

2018년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by