Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Problem in writing a loop

1 visualizzazione (ultimi 30 giorni)
Pragathi
Pragathi il 27 Apr 2014
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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?

Risposte (0)

Questa domanda è chiusa.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by