Say I have two matrices of the form(adsbygoogle = window.adsbygoogle || []).push({});

A = [1 0 0 1 0 1] (1 x 6 row vector)

and

B = [ a b c] (1 x 3 row vector). The number of elements in B = number of 1s in A.

Is there any matrix operation that could be done on A and B that would give me C = [a 0 0 b 0 c]? That is the 1's of A should be replaced with the values in B and zeros left as it is.

I am looking for operations that would not access the individual elements separately (i.e. I am not looking for things like if A(1)==1, C(1)=A(1)*b(1) etc... or inserting zeros.) I am looking for some operation like A*B that would give this result.

Sorry about the cryptic title. I can't really describe it without examples.

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Is there such a matrix operation

**Physics Forums | Science Articles, Homework Help, Discussion**