24小时热门版块排行榜    

查看: 427  |  回复: 0

yanweicumt

银虫 (小有名气)

[求助] matlab循环程序求助

我生成一个有向图,如果当节点只有进入的边,而没有出去的边时,重新执行一次生成图的程序,反之,也要重新执行一次,总之,就是让每个节点,既有in-edge,又有out-edge。
CODE:
while 1
    outnneighbors = zeros(1,n);
    innneighbors = zeros(1,n);
    G = directG(n,dist,thresh);
    Graph.P = pos;
    outcount = 0;
    incount = 0;
for i=1:n
         outneighbors{i} = find(G.A(i,:));%find function - return the all nonzero elements of array (G(i,:)),row
                                 %  即,返回数列的非零值坐在的列数,G中有几个非零数即表示有几个邻居节点,因为G为
                                 %  图的邻接矩阵,如果相邻节点之间存在edge,则取值为1
         outnneighbors(i) = numel(outneighbors{i});%numel function-return the number of elements,n, in array(neighbors{i})
         outcount = outcount +1;
         if outnneighbors (i) ==0
             break;
         else
             inneighbors{i} = find(G.A(:,i));%find function - return the all nonzero elements of array (G(i,:)),row
                                 %  即,返回数列的非零值坐在的列数,G中有几个非零数即表示有几个邻居节点,因为G为
                                 %  图的邻接矩阵,如果相邻节点之间存在edge,则取值为1
             innneighbors(i) = numel(inneighbors{i});%numel function-return the number of elements,n, in array(neighbors{i})
             incount = incount +1;
             if innneighbors (i) ==0
                break;
             end
             if incount >= n
                break;
             end
         end
         if outcount >= n
            break;
         end
      break;
     end
end

请大家帮我看看,这个程序哪里存在问题,谢谢了
G是生成一个有向图,outneighbor 表示out-edge的邻居节点数目总和,inneighbor表示in-edge的节点数目总和。
谢谢了,希望得到大家的回复

[ Last edited by xiegangmai on 2011-5-23 at 23:19 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

相关版块跳转 我要订阅楼主 yanweicumt 的主题更新
信息提示
请填处理意见