MATLAB: I have a 300 x 150 zeros matrix and want to change only the lower triangular elements to 1, How to do that

matricesmatrixonetriangletriangularzero

Everything is in the title really, I need to change the lower triangular elements of this zeros matrix to 1, how can I do this easily?

Best Answer

You don't even need your original zeros matrix (let's say it's called z). Simply make a 15x30 matrix of zeros with the lower left triangle of 1's like this:
z = [tril(ones(15), 0), zeros(15)]