Q(2):Create a 256 x 256 matix with ones in the (i,i+1) position and zeros elsewhere.
Ans.
A=zeros(256);
for x=1:256;
A(x,x+1)=1;
end;
--------------------------
A 256 x 256 matrix with 1's in the (i,i+1) position and zeros elsewhere can be coded as follows:
A=tril(ones(256),1);
B=tril(ones(256),0);
A-B
----------------------
In one line:
A=(tril(ones(256,1))-tril(ones(256),0)imshaow(A)
----------------
No comments:
Post a Comment