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 Center および File ExchangeOperating 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