Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我是Matlab的新手,正在尝试摆脱Java / C ++习惯。
问题是“我如何摆脱这些循环。” 我试图使用nchoosek(n0,2)摆脱其中一个循环,但又出现了另一个问题。(nchoosek的性能) for j=2:n0 for i=1:j-1 %wij is the number of rows of A that have 1 at both column i and column j %summing col i and j to find #of common 1's wij = length(find((A(:,i)+A(:,j))==2)); %store it W(1,j)=wij; %testing whether the intersection of any two columns is too large if wij>= (1+epsilon)*u2; %create and edge between col ij end end end 回答: 我假设A是只有0和1的数组。 然后,您可以通过写入来创建一个nCol-by-nCol数组B,其中各列之间有“距离” B = A'*A; %'# B(i,j) = length(find((A(:,i)+A(:,j))==2)) %# threshold largeIntersection = B >= u2; %# find i,j of large intersections [largeIJ(:,1),largeIJ(:,2)] = find(largeIntersection); %# make sure we only get unique i,j pairs largeIJ = unique(sort(largeIJ,2),'rows'); 更多&回答... |
![]() |
![]() |