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

1 次查看(过去 30 天)
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.

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by