Finding the index of duplicate rows in a cell

4 Ansichten (letzte 30 Tage)
NA
NA am 20 Apr. 2021
Bearbeitet: Jan am 21 Apr. 2021
I have A and B
A = [3,8; 8,9; 8,9; 3,9; 3,9; 3,5; 5,10; 5,10; 3,10; 3,17; 3,17; 11,17; 10,11; 10,11; 3,10];
B = {[3,8;8,9;9,3];[3,5;5,10;3,10];[3,17;3,10;10,11;11,17]};
I want to find indices of all rows in the cell and the repeated rows
I use this code
for i=1:numel(B)
[~,X] = intersect(A,sort(B{i},2),'rows','stable');
index_temp{i} = X;
end
But it does not give me for the repeated rows
Result should be:
index_temp ={[1;2;3;4;5],[6,7,8,9],[10,11,15,13,14,12]}

Akzeptierte Antwort

Jan
Jan am 20 Apr. 2021
Bearbeitet: Jan am 21 Apr. 2021
A = [3,8; 8,9; 8,9; 3,9; 3,9; 3,5; 5,10; 5,10; 3,10; 3,17; 3,17; 11,17; 10,11; 10,11; 3,10];
B = {[3,8;8,9;9,3]; [3,5;5,10;3,10]; [3,17;3,10;10,11;11,17]};
result = cell(1, numel(B)); % Pre-allocate
for k = 1:numel(B)
X = ismember(A, sort(B{k}, 2), 'rows');
result{k} = find(X);
end

Weitere Antworten (0)

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by