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: Help to vectorize a loop with square matrix
Replies: 5   Last Post: Jul 27, 2012 11:32 AM

Advanced Search

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

Posts: 33
Registered: 2/28/05
Re: Help to vectorize a loop with square matrix
Posted: Jul 27, 2012 10:37 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Thursday, July 26, 2012 5:04:24 PM UTC-4, Brandon wrote:
> It's been some time since I've used Matlab, but I need to vectorize the following code for performance reasons. I'm getting caught up on the square matrix R. I understand the concept of replicating vectors to form arrays using repmat() or multiplying vectors by ones(), but I can't wrap my head around this one, thanks.
>
> <SNIP>
> N = 4;
> angle_deg = 0;
> angles = -180:0.1:180;
> g = zeros(size(angles, 2), 1);
> for k = 1:length(angles)
> theta = angles(k);
> % [N x 1]
> n = (0:N-1).';
> % [N x 1]
> x = exp(-1j*pi*n*sin( (theta-angle_deg)*pi/180));
> % [N x N]
> R = (x * x');
> % [N x 1]
> w = ones(N,1)/N;
> % [1 x N]
> wh = w';
> % [1 x 1] = [1 x N]*[N x N]*[N x 1]
> tmp = wh * R * w;
> % [K x 1]
> g(k) = tmp;
> end % for k = 1:length(angles)
> </SNIP>


Ok weird I must have had a typo or pasted incorrectly. It looks fine now. I don't quite understand the methodology you applied to implement it however. Could you describe the process? Thanks.




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.