필터 지우기
필터 지우기

Access subarry from large file and loop through each subarry.

조회 수: 2 (최근 30일)
dipak sanap
dipak sanap 2016년 1월 26일
댓글: dipak sanap 2016년 1월 26일
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.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 1월 26일
편집: Andrei Bobrov 2016년 1월 26일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by