How to get Ones along the diagonal

76 visualizzazioni (ultimi 30 giorni)
SIDDESHA H
SIDDESHA H il 29 Dic 2016
Modificato: David J. Mack il 29 Dic 2016
I need a matrix of size 5x5 with ones along the diagonal and remaining values to be zero. How to get this.

Risposte (1)

David J. Mack
David J. Mack il 29 Dic 2016
Modificato: David J. Mack il 29 Dic 2016
The built-in function DIAG is your friend:
X = diag(ones(5,1))
Greetings, David

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by