Wednesday, December 10, 2008

Interleave


There was some curiosity over this, so here is a suggested solution. Rest of the solutions to follow.

function c = interleave(a, b)

c = zeros(1, length(a) + length(b));
if length(a) > length(b)
c(2 : 2 : 2*length(b)) = b;
c(c == 0) = a;
else 
c(1 : 2 : 2*length(a)) = a;
c(c == 0) = b;
end

2 comments:

Subodh said...

Sir,

Once again, we were barking up the wrong tree. Thanks for the solution.

Regards,
Subodh

Anonymous said...

Sir,
I guess i am still in the C/C++/ JAVA mould. Very Elegant solution indeed!

Mehul