[row2, row1] = ndgrid(1:size(A, 1));
row1 = nonzeros(tril(row1, -1));
row2 = nonzeros(tril(row2, -1));
[uA, ~, destcol] = unique(A);
hasnumber = zeros(size(A, 1), numel(uA));
hasnumber(sub2ind(size(hasnumber), repmat(1:size(A, 1), 1, size(A, 2))', destcol)) = 1;
ismatch = hasnumber(row1, :) + hasnumber(row2, :) == 2;
haspair = sum(ismatch, 2) == 2;
uA = repmat(uA, 1, sum(haspair));
RowIndices = [row1(haspair), row2(haspair)]
PairValues = reshape(uA(ismatch(haspair, :)'), 2, []).'
3 Comments
Guillaume (view profile)
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/464654-find-all-lines-of-a-matrix-which-have-a-matching-pair-of-values#comment_709788
Guillaume (view profile)
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/464654-find-all-lines-of-a-matrix-which-have-a-matching-pair-of-values#comment_709796
Florent Hannard (view profile)
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/464654-find-all-lines-of-a-matrix-which-have-a-matching-pair-of-values#comment_709817
Sign in to comment.