Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 Matlab摆脱循环

我是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');

更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 23:32


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.