Replacing part of an array with another

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일

1 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 11월 8일

편집:

2022년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by