Debasmita Bhoumik
Debasmita Bhoumik

Reputation: 77

How to overlap 2 matrices, where zeros are "transparent"

I have 2 matrices, say

A = [ 0  4  9        B = [ 0  0  2
      0  2  1              1  6  1
      3  0  0 ]            3  9  8 ]

I want the result to be "A overlapped with B".

So I should get:

result = [ 0  4  2
           1  6  1
           3  9  8 ]

Upvotes: 1

Views: 52

Answers (1)

m3tho
m3tho

Reputation: 602

A=[ 0   4   9;       
    0   2   1;     
    3   0   0];     

B=[ 0   0   2;
    1   6   1;
    3   9   8];


result = A;
result( B~=0 ) = B( B~=0 );

Upvotes: 3

Related Questions