Extracting rows from a matrix based on values in columns

 Respuesta aceptada

It's much easier to do this with the newer splitapply rather than the older accumarray:
A = [[1;1;3;2;3;1], rand(6, 3)]
C = splitapply(@(rows) {rows}, A(:, 2:end), A(:, 1))

2 comentarios

I am up-voting even though ...
;)
Awesome, thanks!

Iniciar sesión para comentar.

Más respuestas (1)

for n=2:4, C_temp(:,n-1) = accumarray(A(:,1),A(:,n),[],@(n){n}); end
for m=1:size(C_temp,1), C{m} = cell2mat(C_temp(m,:)); end

Categorías

Más información sobre Mathematics and Optimization en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Oct. de 2017

Comentada:

el 8 de Oct. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by