MATLAB: Help Creating the following matrix

helpMATLAB

Create a matrix using functions zeros(), ones() and/or eye()
3 0 2 2
0 3 2 2
0 0 3 0

Best Answer

Very easy, really.
A = zeros(3,4);
A(1,1) = 3*eye;
A(1,3) = 2*ones;
A(1,4) = 2*ones;
A(2,2) = 3*eye;
A(2,3) = 2*ones;
A(2,4) = 2*eye;
A(3,3) = 3*ones;
A =
3 0 2 2
0 3 2 2
0 0 3 0
Oh, darn. This is actually your homework, and I just did it for you. (Did you notice I use eye there sometimes, and ones other times, but for absolutely no good reason for that choice?)
Anyways ... maybe, just maybe, there is a shorter way to solve it.
I got it now! This should work, in only one line:
A = [3 0 2 2;0 3 2 2;0 0 3 0]*ones + zeros;
As you can see, it uses both ones and zeros. I could even have included a use of eye in there too.
A = eye(3)*[3 0 2 2;0 3 2 2;0 0 3 0]*ones + zeros;