Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 ];

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 11 Mai 2016
index=A~=0;
C=B;
C(index)=A(index);

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by