MATLAB: A null assignment can have only one non-colon index

a null assignment can have only one non-colon index

B=zeros(23,23)
for r=1:23;
for n=1:23;
if r==n
B(r,n)=A(r,n);
else
B(r,n)=[];
end
end
end
A is a symmetric 23*23 matrix and I want to remove all the other values except r=n. It gives me an "A null assignment can have only one non-colon index" error

Best Answer

B=zeros(23,23)
for r=1:23;
for n=1:23;
if r==n
B(r,n)=A(r,n);
else
B(r,n)=NaN;
end
end
end