How can I extract the upper triangular part of a matrix and set only the off-diagonal values to pi?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Peter Isson
el 3 de Jul. de 2016
Respondida: Andrei Bobrov
el 3 de Jul. de 2016
Hi all,
I got a matrix A = ones(1,1).
When I use triu(ones(1,1)) the lower triangular part of the matrix gets zero.
What I need to do is that instead of zero it gets pi.
That means: 1 1 1 pi 1 1 pi pi 1
Is there any possibility to integrate this into the triu function?
Thanks!
0 comentarios
Respuesta aceptada
Jos (10584)
el 3 de Jul. de 2016
Your statements make no sense: ones(1,1) wil give you the scalar 1 ...
I think you are after something like this:
N = 3
A = ones(N)
tf = tril(true(N),-1)
A(tf) = 2
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!