MATLAB: How to get elegantly an upper triangle random matrix (0 elsewhere)

matrixmatrix manipulation

I have seen the triu and tril functions, but I can't use them to set to 0:
A = rand(4);
tril(A)=0; % won't work
any idea, other than using 2 for loops?

Best Answer

triu(A,1)