How to copy or transfer a portion of matrix to another at same location?

2 ビュー (過去 30 日間)
mathango
mathango 2016 年 5 月 11 日
回答済み: Fangjun Jiang 2016 年 5 月 11 日
Hi, Is there a way to copy or transfer a portion of matrix A (nonzero values) to another matrix B at same location?
for example:
A = [ 0 0 0 0 0; 0 1 0 1 0; 0 1 0 1 0; 0 0 0 0 0 ];
B = [ 8 8 8 8 8; 8 8 8 8 8; 3 3 3 3 3; 2 2 2 2 2 ];
% desired answer is
C = [ 8 8 8 8 8; 8 1 8 1 8; 3 1 3 1 3; 2 2 2 2 2 ];

採用された回答

Fangjun Jiang
Fangjun Jiang 2016 年 5 月 11 日
index=A~=0;
C=B;
C(index)=A(index);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by