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: Can my code be made more efficient using MATLAB's vectorization?
Replies: 4   Last Post: Feb 16, 2013 6:55 PM

Advanced Search

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

Posts: 8,727
Registered: 7/26/08
Re: Can my code be made more efficient using MATLAB's vectorization?
Posted: Feb 14, 2013 3:26 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Jeff" wrote in message <kfj82r$k50$1@newscl01ah.mathworks.com>...

>
> P_f = zeros(t_end,N);
> for m=1:t_end
> P_f = W(m,:).^2.*evals;
> end
> P_f = -P_f./N;
>


Bad: you post an untested code (anyone can spot an obvious mistake), so I do the same:

P_f = bsxfun(@times, W.^2, evals/(-N));

% Bruno



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.