Access subarry from large file and loop through each subarry.

1 visualización (últimos 30 días)
Hi all,I have an array A as follows,
1 65 63 41
1 32 1 66
1 51 453 66
2 12 12 251
2 54 544 84
3 848 484 48
3 44 484 64
3 44 646 644
3 545 4546 454
I want to write a for loop for every subarray if A(i,1) == A(i+1,1)
Like, for loop for each of these cases
A(1:3,:)
A(4:5,:)
A(6:10,:)
Any help is appreciated thanks.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 26 de En. de 2016
Editada: Andrei Bobrov el 26 de En. de 2016
A_out = accumarray(A(:,1),(1:size(A,1))',[],@(x){A(x,:)});
other:
b = unique(A(:,1));
n = numel(b);
A_out = cell(n,1);
for ii = 1:n
A_out{ii} = A(A(:,1) == b(ii),:);
end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by