Replacing 1's in a vector 'a' with elements of another vector 'b' where a and b are not equal?

I have two vectors 'a' and 'b' in the following form:
a=[nan nan 1 1 nan 1 nan 1 1 1 1]
b=[2 3 4 5 6 7 8]
I want to replace all the 1's in vector 'a' by elements in vector 'b' so that I have a vector 'c' in the following shape:
c=[nan nan 2 3 nan 4 nan 5 6 7 8]
I have vectors 'a' and 'b' having thousands of elements and I want to replace all 1's in vector 'a' by elements in vector 'b' .
Please help
Thanks

 Accepted Answer

>> a = [NaN,NaN,1,1,NaN,1,NaN,1,1,1,1];
>> b = [2,3,4,5,6,7,8];
>> a(a==1) = b
a =
NaN NaN 2 3 NaN 4 NaN 5 6 7 8

Asked:

on 22 Jul 2015

Commented:

on 22 Jul 2015

Community Treasure Hunt

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

Start Hunting!