Finding the index of duplicate rows in a cell

5 visualizzazioni (ultimi 30 giorni)
NA
NA il 20 Apr 2021
Modificato: Jan il 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]}

Risposta accettata

Jan
Jan il 20 Apr 2021
Modificato: Jan il 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

Più risposte (0)

Categorie

Scopri di più su Language Fundamentals 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