Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: a very time consumming code
Replies: 5   Last Post: Sep 28, 2013 4:33 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 12
Registered: 3/28/12
Re: a very time consumming code
Posted: Sep 28, 2013 2:20 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> 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.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.