How to add values to diagonal of a matrix
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
k=1;
n=6;
for i=1:6
for j=1:6
A(i,j)=?
I need to have values in the diagonal going from 1:6 but I keep getting an error.
0 Kommentare
Antworten (1)
David Hill
am 26 Aug. 2019
x=diag(1:6);
Is the diagonial matrix with 1:6 on the diagonal.
2 Kommentare
David Hill
am 26 Aug. 2019
I am not sure what you want to do, but why not just change your input?
k=zeros(6);
k(1,1)=1;
x=diag(1:6);
k+x;
Yes, the sizes need to be the same, but why not just add zeros to match the size?
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!