Finding the index of duplicate rows in a cell
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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]}
0 Kommentare
Akzeptierte Antwort
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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices 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!