How to operate on specific diagonal elements of a matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ahmad Gad
el 27 de Nov. de 2017
Comentada: Ahmad Gad
el 27 de Nov. de 2017
Hello everyone.
I am having a matrix k with size (20 x 20), for which, I need to replace some of the diagonal elements with ones. I constructed a vector v including the indices of the elements to be replaced, and applied the following code, but I is not working as I wanted.
k = rand(20);
u = [1; 3; 6; 11; 16; 20];
k(u(:,1),u(:,1)) = 1;
He is replacing the diagonal members and other members as if he is including all combinations of the rows and columns. How can I edit this to get only the diagonal members corrected?
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!