How to split array based condition

20 visualizaciones (últimos 30 días)
Rajib Deyana
Rajib Deyana el 30 de Mayo de 2018
Editada: KSSV el 30 de Mayo de 2018
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.

Respuestas (1)

KSSV
KSSV el 30 de Mayo de 2018
Editada: KSSV el 30 de Mayo de 2018
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'})

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by