Azzera filtri
Azzera filtri

Access subarry from large file and loop through each subarry.

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 26 Gen 2016
Modificato: Andrei Bobrov il 26 Gen 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by