Create a Matrix with a specific main diagonal
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adzlxix
el 30 de Nov. de 2015
I want to create a matrix of all one's with the main diagonal of value n.
0 comentarios
Respuesta aceptada
Thorsten
el 30 de Nov. de 2015
val = 50; N = 10;
X = diag(repmat(val-1, 1, 10)) + ones(N)
0 comentarios
Más respuestas (3)
dpb
el 30 de Nov. de 2015
Multiple ways possible; one--
>> N=5; % diagonal value
>> sz=3; % size
>> m=ones(sz)+diag(repmat(N-1,1,sz))
m =
5 1 1
1 5 1
1 1 5
>>
doc diag % for details on optional arguments for different resulting types
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!