How can I get elegantly an upper triangle random matrix (0 elsewhere)?

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?

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 5월 31일
편집: Andrei Bobrov 2014년 5월 31일
triu(A,1)

추가 답변 (0개)

질문:

2014년 5월 31일

편집:

2014년 5월 31일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by