Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Problem in writing a loop
조회 수: 1 (최근 30일)
이전 댓글 표시
The following program is for p=3. I am facing a problem to write a loop for the program for any p value where p is prime number.
p=3;
a=0:p-1;
s = mod(a'*a,p);
l=[repmat(a,p,1)]';
s0=repmat(s(1,:),p,1);
g0=mod(s0+l,p)+1;
ii=bsxfun(@plus,g0,a*p);
jj=ndgrid(a+1);
c0=zeros(p,p^2);
c0(sub2ind([p,p^2],jj,ii)) = 1;
c0=flipud(c0);
c0=circshift(c0,[1 0])
s1=repmat(s(2,:),p,1);
for i=1:p
mat=s1(1,:);
mat1=circshift(mat,[0 -(i-1)]);
s1(i,:)=mat1;
end
ii=bsxfun(@plus,s1+1,a*p);
jj=ndgrid(a+1);
c1=zeros(p,p^2);
c1(sub2ind([p,p^2],jj,ii)) = 1
s2=repmat(s(3,:),p,1);
for i=1:p
mat=s2(1,:);
mat1=circshift(mat,[0 -(i-1)]);
s2(i,:)=mat1;
end
ii=bsxfun(@plus,s2+1,a*p);
jj=ndgrid(a+1);
c2=zeros(p,p^2);
c2(sub2ind([p,p^2],jj,ii)) = 1
Sir,is there any way to write the program using loops with p value as any prime number?
댓글 수: 0
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!