Revision 7faed1a32db1958b5677971c7ab5da823d04f1c9 authored by Peter Carlton on 12 October 2018, 03:05:39 UTC, committed by Peter Carlton on 12 October 2018, 03:05:39 UTC
1 parent d5900f9
spiral.m
function s = spiral (n)
%makes n-by-n square spiral matrix
s=zeros(n);
i=ceil(n/2);
j=ceil(n/2);
s(i,j)=1;
if(n==1), return, end
k=1;d=1;
for p=1:n
q=1:min(p,n-1);
j=j+d*q;
k=k+q;
s(i,j)=k;
if(p==n),return,end
j=j(p);
k=k(p);
i=i+d*q';
k=k+q';
s(i,j)=k;
i=i(p);
k=k(p);
d=(-d);
end
Computing file changes ...