Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Brandon
Posts:
33
Registered:
2/28/05


Re: Help to vectorize a loop with square matrix
Posted:
Jul 27, 2012 10:37 AM


On Thursday, July 26, 2012 5:04:24 PM UTC4, 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:N1).'; > % [N x 1] > x = exp(1j*pi*n*sin( (thetaangle_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.



