Randomly create lower and upper of matrix separately.
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abe
am 28 Dez. 2014
Kommentiert: Abe
am 28 Dez. 2014
I would like to create a randomly lower triangle of the matrix, and then create an upper triangle of matrix separately. After that I want to compound both of these in one matrix. More deeply, I want to control each cell in both half matrix.
3 Kommentare
John D'Errico
am 28 Dez. 2014
What do you mean to "control each cell"?
You can always access any element of a matrix.
Akzeptierte Antwort
Shoaibur Rahman
am 28 Dez. 2014
l = tril(rand(m,n),-1); % lower triangle
u = triu(rand(m,n),1); % upper triangle
d = diag(rand(1,m),0); % diagonal elements
A = l+u+d % final matrix, combined all
If you don't want to generate the diagonal elements separately, then replace either -1 in lower triangle or 1 in upper triangle by 0, and then A = l+u
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!