Replacing part of an array with another

3 visualizzazioni (ultimi 30 giorni)
L'O.G.
L'O.G. il 8 Nov 2022
Modificato: KSSV il 8 Nov 2022
How do I replace the diagonal of one 2d array with the diagonal of another? The arrays have the same size.

Risposta accettata

KSSV
KSSV il 8 Nov 2022
Modificato: KSSV il 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

Più risposte (0)

Categorie

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

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by