필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
K_Dot
K_Dot 2017년 7월 16일
편집: the cyclist 2017년 7월 16일
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에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by