Replacing part of an array with another

4 vues (au cours des 30 derniers jours)
L'O.G.
L'O.G. le 8 Nov 2022
Modifié(e) : KSSV le 8 Nov 2022
How do I replace the diagonal of one 2d array with the diagonal of another? The arrays have the same size.

Réponse acceptée

KSSV
KSSV le 8 Nov 2022
Modifié(e) : KSSV le 8 Nov 2022
A = rand(4) ;
B = rand(4) ;
n = size(A,1);
A(1:(n+1):end) = diag(B) ; % repalce diagonal elements of A with diagonal elements of B

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by