Replacing part of an array with another

조회 수: 3 (최근 30일)
L'O.G.
L'O.G. 2022년 11월 8일
편집: KSSV 2022년 11월 8일
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