Why is Matlab producing a [1 1] matrix after running a loop?
Show older comments
I have the code
%%Parameters
N = 20;
omega = linspace(0,1,100);
theta = linspace(0,2*pi,100);
varrho = linspace(0,1,100);
psi = linspace(0,2*pi,100);
[varrhos,psis] = meshgrid(varrho,psi); % create mesh grid
omegas = omega(2)-omega(1);
thetas = theta(2)-theta(1);
%%Interpolate
Rs = zeros(size(varrhos)); % preallocate the memory
for n=1:length(omega)
for m=1:length(theta)
f = @(rho,theta) sinc(((1/20)*rho-n*omegas)./omegas).*...
((sin((1/2)*(N-1)*(theta-m*thetas)))./(N*sin((theta-m*thetas)/2))).*...
exp(-1i*rho/2).*exp(-1i*(rho.*varrhos(n,m)+theta.*psis(n,m)));
Rs = -(10/pi)*Dn(n,m).*(integral2(f,0,1,0,2*pi));
end
end
which should produce a 100 x 100 matrix, however, size(Rs) = 1 1.
Note that we calculate Dn via
Dn = zeros(size(omega)); % preallocate the memory
for n = 1:length(omega)
for m = 1:length(theta)
f= @(xx,zz)R(xx,zz).*exp(20*1i*n.*omegas.*...
((sin(m.*thetas)).*xx+(cos(m.*thetas)).*zz));
Dn(n,m) = -exp((10*1i*n.*omegas)./(40*pi)).*integral2(f,0,1,0,1);
end
end
with
phi = @(x)(x>0).*exp(-1./x.^2);
R = @(xx,zz) phi(xx).*phi(1-xx).*phi(zz).*phi(1-zz);
My question is: what am I doing wrong? I run a loop and should get 100 x 100 matrix
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!