I'm creating a diagonal matrix in MATLAB using eye(3)
. How can I assign the number "2" only to the elements under the main diagonal?
The command tril
has an extra argument that controls which lower triangular exactly to use.
A = eye(3) + 2*tril(ones(3), -1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With