如何制作具有相同行数但不同列数的10
矩阵的交集?
目标是找到10
矩阵的公共列。
如何减少这些行:
B1 = intersect(A1',A2','rows')';
B2 = intersect(B1',A3','rows')';
B3 = intersect(B2',A4','rows')';
B4 = intersect(B3',A5','rows')';
B5 = intersect(B4',A6','rows')';
B6 = intersect(B5',A7','rows')';
B7 = intersect(B6',A8','rows')';
B8 = intersect(B7',A9','rows')';
B9 = intersect(B8',A10','rows')';
答案 0 :(得分:2)
假设A1
,A2
,A3
.... A10
为10个输入矩阵,请查看这是否适合您 -
A = cat(1,{A1},{A2},{A3},.....{A10}) %// concatenate all variables into a cell array
A = cellfun(@(x) x.',A,'uni',0) %//'# transpose each cell, so that number of columns
%// corresponding to all matrices is the same
%// Get intersecting rows for each pair from A and keeping the intersecting output
%// for comparison against the next one.
out = A{1}; %// iInitiliaze with the first cell that is the first matrix
for iter = 2:numel(A)
out = intersect(A{iter},out,'rows'); %// find intersection for each matrix
%// against the running intersection result
end
result = out.' %//# desired output