Given an nxn matrix A, how do I produce a lower triangular matrix with ones on the diagonal?

1 view (last 30 days)
Given an nxn matrix A, how do I produce a lower triangular matrix with ones on the diagonal?
I tried
A = rand(n,n);
L = tril(A,1) + diag(ones(1, size(A,1))) ;
but it isn't working.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 23 Sep 2019
tril(A,-1)+eye(n)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!