Finding the index of duplicate rows in a cell

3 次查看(过去 30 天)
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]}

采纳的回答

Jan
Jan 2021-4-20
编辑:Jan 2021-4-21
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 个)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by