【发布时间】:2013-12-31 18:49:52
【问题描述】:
我正在尝试获取所有列和列组合之间可用的所有交叉点的所有计数。
%I have a matrix of overlaps something like this :
colHeader = {'var1','var2','var3','var4','var5'};
rowHeader = {'type1','type2','type3','type4','type5','type6','type7'};
overlap = [1,1,1,1,0;0,0,0,1,1;1,1,0,1,0;0,0,1,1,0;0,1,0,1,1;0,1,1,1,0;1,0,0,1,0];
%now i would like to get the count of overlap for all the columns variations (i.e. var1&var2 ...
%var5&var1 at the first level, at the second level (var1&var2)&var3 etc. )
%the output in this case for level 1 and 2 is simple enough
f = @(a,b) a&b
mat= zeros(5,5);
for i=1:5
for j=1:5
mat(i,j) = sum(f(overlap(:,i),overlap(:,j)));
end
end
% 3 2 1 3 0
% 2 4 2 4 1
% 1 2 3 3 0
% 3 4 3 7 2
% 0 1 0 2 2
% where the diagonal is the first level of overlap and the rest are the relationships between the
% different variables
% i can continue in this fashion but not only is this ugly, it becomes not practical when dealing
%with
% bigger matrixes
% So the problem is how to implement this for a big binary matrix in a manner that will return all
% levels of intersection ?
【问题讨论】:
-
+1 有趣的问题!
标签: matlab intersection overlap