Access subarry from large file and loop through each subarry.

1 回表示 (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by