How to split array based condition

23 次查看(过去 30 天)
Rajib Deyana
Rajib Deyana 2018-5-30
编辑: KSSV 2018-5-30
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
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'})

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by