keep the index of removed array in cell
Show older comments
I have
M = [12,13; 6,12; 6,13; 7,8; 4,5; 5,6; 9,14; 1,2; 1,5; 13,14; 2,5; 4 9];
S = {[7,8],[6,12,13],[4,5,6,9,13,14],[1,2,5]};
I removed some of the rows in M to get M_New
[~,X] = setdiff(sort(M,2),sort([12 13; 9 14; 2,5],2),'rows','stable');
M_New = M(X,:);
Use below function to find indices of M that matches to S
U = @(v)(find(sum(any(v==permute(M_New,[1,3,2]),2),3)==2))';
ele_in = cellfun(U,S,'uni',0);
For finding the orginal index I use this code
Temp = cellfun(@(x)find(all(ismember(M,M_New(x,:)),2)),ele_in,'uni',0);
But it gives me this result
temp={[4],[1;2;3],[3;5;6;7;10;12],[8;9;11]}
I want to have this result
temp={[4],[2;3],[3;5;6;10;12],[8,9]}
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!