Replacing part of an array with another

4 次查看(过去 30 天)
How do I replace the diagonal of one 2d array with the diagonal of another? The arrays have the same size.

采纳的回答

KSSV
KSSV 2022-11-8
编辑:KSSV 2022-11-8
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by