Access subarry from large file and loop through each subarry.

1 vue (au cours des 30 derniers jours)
dipak sanap
dipak sanap le 26 Jan 2016
Commenté : dipak sanap le 26 Jan 2016
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.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 26 Jan 2016
Modifié(e) : Andrei Bobrov le 26 Jan 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by