> Yeah, I was just coming back to 'fess up I'd somehow gotten eyes crossed > and was thinking the earlier definition was getting trashed -- you're > correct it doesn't. > > function [res] = binCross(a,b,cr) > s=length(a); > mui = rand(1,s) < cr; > mpo = mui<0.5; > res= a.*mpo + b.*mui; > fx=randi(s); > res(fx)=b(fx); > end > > However, since mui is logical [0,1], then mui<0.5; --> mui==0; --> ~mui > > One of the latter may be faster than redoing the <0.5 computation (I'd > think the mpo=~mui and perhaps not store it at all but use in place. > > res= a.*~mui + b.*mui; > > I've also not tried timing the difference between operations on the > logical as opposed to casting the logical to double first -- that may > not help any but can't hurt to test just to see if does make any difference. > > --
TRhank you again for helping, unfortunately, the code you proposed takes as much time as mine.