I want to find the 1's in first column and compare it with all other columns and if there is a matching column then count 1 and then second column with remaining columns and so on, but it's not working in my code. I find the value of only one column in this code.
function CNmat=getCNMatrix(adj,col) clc; adj=[0 1 1 1 1 0; 1 0 1 1 0 1; 0 0 0 1 0 1; 1 0 1 0 0 1; 1 0 0 1 0 1; 0 0 0 0 1 0]; col=1; [r,c]=size(adj); %for col=1:c
[xi,xj]=find(adj(:,col)==1); withOne=adj(xi,:); [zr,zc]=find(withOne==1); for j=1:c if (j==col) continue; end CNmat(j)=length(find(zc==j)); endFor eg:,The result of this code is : ans = 0 0 2 2 0 3
It means that when I take the 1's of first column and compare it with other columns, there is no corresponding elements are same in column 2 with column 1.On the other hand, on columns 3 and 4 there are 2 1's same as in column 1 and on column 6 there are 3 1's matches with column 1.But, I want this as a matrix by taking each column's 1 and match it with succeeding columns.
Best Answer