ones and diagonal matrices in one Matrix

1 view (last 30 days)
Hello, everyone I want a matrix where in the diagonal i want specific values and the rest arrays i want to have the same value. I have attach the matrix i want to make. How can i do that, when i have already make the diagonal.
Thank you, Dimitris

Accepted Answer

Guillaume
Guillaume on 14 May 2015
Edited: Guillaume on 14 May 2015
There are many ways to generate such a matrix. One possible way:
diagvalue = 5;
othervalue = 7;
diaglength = 10;
m = eye(diaglength) .* diagvalue + ~eye(diaglength) .* othervalue

More Answers (1)

Jan
Jan on 14 May 2015
When d is "var(d_1^2)" and v is the vector added to the diagonal:
Result = repmat(d, n, n) + diag(v);

Categories

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

Community Treasure Hunt

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

Start Hunting!