Why is Matlab producing a [1 1] matrix after running a loop?

3 次查看(过去 30 天)
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

采纳的回答

the cyclist
the cyclist 2017-7-16
编辑:the cyclist 2017-7-16
I think you want
Rs(n,m) = ...
in place of
Rs = ...
inside the loop.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by