如何修复:索引超过了数组元素的数量(2)



我是Matlab的新手,我遇到过一个显示偶极辐射模式的程序,但当我尝试运行该程序时,出现了以下错误。

clear all
clc
format short g
syms z theta lambda R
prompt = 'Enter the frequency=? '; 
freq = input(prompt);
prompt = 'Enter the antenna size=? '; 
length = input(prompt);
L = round(length*freq/3e8,3)*lambda; %Length of antenna in terms of lambda
k0 = 2*pi/lambda; %Phase constant
z0 = 120*pi; %Intrinsic impedance
I = sin(k0*(L/2-abs(z))); %Current distribution
E(theta,lambda,R) = (1i*z0*k0*sin(theta)*exp(-1i*k0*R)/(4*pi*R))*int(I*2*cos(k0*z*cos(theta)),z,0,L/2); %E-field at farzone
A=(1i*z0*k0*exp(-1i*k0*R)/(4*pi*R));
p=(sin(theta)*int(I*2*cos(k0*z*cos(theta)),z,0,L/2)); %The theta part of the E-field with the constant term
%Elimination the constant term from 'p'--%
Q=(int(diff(p),theta));
F= factor(Q,theta);
field_pattern(theta) = simplify(p/F(1));
%----------------------------------------%
new(theta)=simplify(Q/F(1));
new2 = matlabFunction(new);

%------------------------------------------3D-pattern plot--------------------% 
v=0.1:pi/499:1*pi;
t=0:pi/499:2*pi;
t2=0:pi/499:pi;
[T,U] = meshgrid(t,v);
[T2,U2]=meshgrid(t2,v);
X = abs(new2(U)).*sin(U).*cos(T); 
Y = abs(new2(U)).*sin(U).*sin(T); 
Z = abs(new2(U)).*cos(U);

X2 = abs(new2(U2)).*sin(U2).*cos(T2); 
Y2 = abs(new2(U2)).*sin(U2).*sin(T2); 
Z2 = abs(new2(U2)).*cos(U2);

figure (1);
surf(X,Y,Z,abs(new2(U)));
shading interp
axis vis3d
axis equal
lighting gouraud
set(gca,'xtick',[])
set(gca,'xticklabel',[])
set(gca,'ytick',[])
set(gca,'yticklabel',[])
set(gca,'ztick',[])
set(gca,'zticklabel',[])
figure (2);
surf(X2,Y2,Z2,abs(new2(U2)));
shading interp
axis vis3d
axis equal
lighting gouraud
set(gca,'xtick',[])
set(gca,'xticklabel',[])
set(gca,'ytick',[])
set(gca,'yticklabel',[])
set(gca,'ztick',[])
set(gca,'zticklabel',[])
%---------------------------------E-field radiation pattern plot--------------%     

figure (3);
theta3=0:0.01:2*pi;

polar(theta3,abs(field_pattern(theta3))); %E-field radiation pattern
title(['Antenna length: ' num2str(round(length*freq/3e8,3))]);
view([90 -90]);


-错误-

符号/因子错误(第107行(重数=双(c{k+1}(;

偶极模式中的误差(第20行(F=因子(Q,θ(;

我试着输入示例中所示的值(频率:3e8,天线大小:2.7(,但在示例能够生成数字时出现了错误。我应该调整什么来消除错误?

在factor.m中,multiplicity似乎试图访问c的第(k+1(个单元格,其中k max是numel(c(。它应该总是抛出一个异常,其中c没有第(k+1(个单元格。它可能是原始库中的一个错误。

相关内容

  • 没有找到相关文章

最新更新