N=10000;m0=3;m=3;adjacent_matrix=sparse(m0,m0);fori=1:m0forj=1:m0ifj==iadjacent_matrix(i,j)=1;endendendadjacent_matrix=sparse(adjacent_matrix);node_degree=zeros(1,m0+1);node_degree(2:m0+1)=sum(adjacent_matrix);foriter=4:Nitertotal_degree=2*m*(iter-4)+6;cum_degree=cumsum(node_degree);choose=zeros(1,m)%%%r1=rand(1)*total_degree;fori=1:iter-1if(r1=cum_degree(i))&(r1cum_degree(i+1))choose(1)=i;breakendendchoose(1)%%r2=rand(1)*total_degree;fori=1:iter-1if(r2=cum_degree(i))&(r2cum_degree(i+1))choose(2)=i;breakendendwhilechoose(2)==choose(1)r2=rand(1)*total_degree;fori=1:iter-1if(r2=cum_degree(i))&(r2cum_degree(i+1))choose(2)=i;breakendendendchoose(2)%%%r3=rand(1)*total_degree;fori=1:iter-1if(r3=cum_degree(i))&(r3cum_degree(i+1))choose(3)=i;breakendendwhile(choose(3)==choose(1))|(choose(3)==choose(2))r3=rand(1)*total_degree;fori=1:iter-1if(r3=cum_degree(i))&(r3cum_degree(i+1))choose(3)=i;breakendendendchoose(3)%%%fork=1:mz=choose(k)adjacent_matrix(z,iter)=1;adjacent_matrix(iter,z)=1;endnode_degree=zeros(1,iter+1);node_degree(2:iter+1)=sum(adjacent_matrix);endsavedataadjacent_matrix;???Subscriptindicesmusteitherberealpositiveintegersorlogicals.Errorin==d:\MATLAB6p5\work\Untitled3.mOnline63==adjacent_matrix(z,iter)=1;运行到adjacent_matrix(z,iter)=1;lz可以单步一下看到,z为零,在MATLAB里,下标是不能为零的。lz再修改一下您的程序吧。呵呵z=0iteriter=4