Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Vectors must be the same lengths error

1 visualizzazione (ultimi 30 giorni)
Burak
Burak il 8 Apr 2013
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hi , here is my code.I got this error Vectors must be the same lengths.Can you help me to solve the problem.Thanks. if true format long
tic
N_cut=20;
eps0=(10^-9)/(36*pi);
mu0=4*pi*10^-7;
epsr1=1.;
epsr2=2.;
mur1=1.;
mur2=1.;
eps1=epsr1*eps0;
eps2=epsr2*eps0;
mu1=mur1*mu0;
mu2=mur2*mu0;
freq=6*10^8;
omeg=2*pi*freq;
k=omeg*sqrt(eps1*mu1);
lambda=2*pi/k;
R=0.4;
phi=0;
for n=1:N_cut
A=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
A(isnan(A))=0;
bes_kur(n)=A;
B=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
B(isnan(B))=0;
han_kur(n)=B;
C=-n.*sqrt(pi.*k./(2.*R)).*besselj(n+0.5,k.*R)+k.*sqrt(pi.*k.*R./2).*besselj(n-0.5,k.*R);
C(isnan(C))=0;
bes_kur_der(n)=C;
D=-n.*sqrt(pi.*k./(2.*R)).*besselh(n+0.5,2,k.*R)+k.*sqrt(pi.*k.*R./2).*besselh(n-0.5,2,k.*R);
D(isnan(D))=0;
han_kur_der(n)=D;
a(n)=(1i.^(-n)).*(2.*n+1)./(n.*(n+1));
b(n)=(-a(n)).*bes_kur_der(n)./han_kur_der(n);
c(n)=(-a(n)).*bes_kur(n)./han_kur(n);
end
for n=1:N_cut
L1=legendre(n,cosd(theta));
L11=legendre(n-1,cosd(theta));
L2(n,theta)=L1(2,:);
if n==1
L3(n,theta)=0.;
else
L3(n,theta)=L11(2,:);
end
L2_der(n,theta)=(1./(1-(cosd(theta)).^2)).*((-n).*cosd(theta).*L3(n)+((n+1).*L2(n)));
E_theta(n,theta)=(1i/k*R)*exp(-1i*k*R)*cosd(phi)*((1i.^n).*((b(n).*sind(theta).*L2_der(n,theta)-c(n).*L3(n,theta)./sind(theta))));
end
F_Etheta=sum(E_theta,2);
theta=1:length(F_Etheta):179;
figure
plot(theta,abs(F_Etheta))
grid on
end
  1 Commento
Tobias
Tobias il 8 Apr 2013
Does it specify a line inwhich the problem lies?

Risposte (2)

Jan
Jan il 8 Apr 2013
Please read and post the complete error message. It contains the failing line, which is very useful for solving the problem.
You can use the debugger also:
dbstop if error
Then run the program again. Matlab stops when the error occurs and you can inspect the local variables to find out, which operation is not well defined.

Walter Roberson
Walter Roberson il 8 Apr 2013
Why are you using
theta=1:length(F_Etheta):179;
The only way that can be the same length as F_Etheta is if
floor(180/length(F_Etheta)) = length(F_Etheta)
or approximately
179 = length(F_Etheta)^2
so
length(F_Etheta) = sqrt(179)
which is between 13 and 14.
If you experiment with 1:13:179 then its length is 14, and 1:14:179 has length 13, so even if your length happens to be in the right approximate range, it is not possible to match the length of the two vectors.
  1 Commento
Burak
Burak il 8 Apr 2013
I want to scale x-axis as thetas and y-axis as F_Etheta , and how can I solve this problem even if I correct it as you told above.

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by