MATLAB: How to can I create a square diagonal matrix and insert variables into it

diagonallc circuitMATLABmatrixprojectsquaresquare matrix

Hello,
I need to create a 500×500 matrix that looks like this
[0 0 0 0 0 x
0 0 0 0 x 0
0 0 0 x 0 0
0 0 y 0 0 0
0 y 0 0 0 0
y 0 0 0 0 0 ]
now i know that i can use eye(0,0) command and use the fliplr() to create an inverse identity matrix. but i just need to know how to add variables into it.....
any ideas?
your help is appreciated
THANK YOU :)

Best Answer

A=zeros(6)
[n,m]=size(A);
idx=sub2ind([n m],1:n,n:-1:1)
x=5;
y=10;
A(idx)=[x x x y y y ]