MATLAB出现?Subscript indices must either be real positive inte
来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/06/13 22:51:18
MATLAB出现?Subscript indices must either be real positive integers or logicals
clear all %a .m
Rh=input('请输入环半径,Rh=');
I0=input('请输入环电流,I0=');
mu0=4*pi*1e-7;
C0=mu0/(4*pi)*10; %归常数
Nh=20; %电流环分段数
x=linspace(-3,3,Nh);y=x; %确定观测点的范围
theta0=linspace(0,2*pi,Nh+1); %环的圆周角分段
thetal=theta0(1,Nh);
y1=Rh*cos(thetal); %环各段矢量的起点坐标y1,z1
z1=Rh*sin(thetal);
theta2=theta0(2:Nh+1);
y2=Rh*cos(theta2); %环各段矢量的终点坐标y2,z2
z2=Rh*sin(theta2);
xc=0;yc=(y2+y1)/2;zc=(z2+z1)/2; %计算环各段矢量中的点的坐标分量
dlx=0;dly=y2-y1;dlz=z2-z1; %计算环各段矢量d1的3个分量,x1=x2=0
NGx=Nh;NGy=NGx; %确定网格线数
for i=1:NGx
rx=x(j)-xc,ry=y(i)-yc,rz=0-zc; %计算矢径r的3个长度分量,P点z=0
r3=sqrt(rx.^2+ry.^2+rz.^2).^3; %计算r^3
dlXr_x=dly.*rz-dlz.*ry; %计算叉乘积dl×r的x和y分量,z分量为0
dlXr_y=dlz.*rx-dlx.*rz;
Bx(i,j)=sum(C0*dlXr_x./r3); %把环各段产生的磁场分量累加
By(i,j)=sum(C0*dlXr_y./r3);
B=(Bx.^2+By.^2).^0.5; %计算B的大小
end
subplot(1,2,1),quiver(x,y,Bx,By); %用quiver画磁场矢量图
xlabel('x'),ylabel('y')
axis([-3,3,-3,3])
subplot(1,2,2)
mesh(x,y,B); %画磁场大小分布图
xlabel('x'),ylabel('y'),zlabel('v')
————————————————————————————————————————————
Subscript indices must either be real positive integers or logicals.
Error in ==> dianci at 19
rx=x(j)-xc,ry=y(i)-yc,rz=0-zc; %计算矢径r的3个长度分量,P点z=0
请问错在了那里?在十九行以下还出现什么错误了吗?
clear all %a .m
Rh=input('请输入环半径,Rh=');
I0=input('请输入环电流,I0=');
mu0=4*pi*1e-7;
C0=mu0/(4*pi)*10; %归常数
Nh=20; %电流环分段数
x=linspace(-3,3,Nh);y=x; %确定观测点的范围
theta0=linspace(0,2*pi,Nh+1); %环的圆周角分段
thetal=theta0(1,Nh);
y1=Rh*cos(thetal); %环各段矢量的起点坐标y1,z1
z1=Rh*sin(thetal);
theta2=theta0(2:Nh+1);
y2=Rh*cos(theta2); %环各段矢量的终点坐标y2,z2
z2=Rh*sin(theta2);
xc=0;yc=(y2+y1)/2;zc=(z2+z1)/2; %计算环各段矢量中的点的坐标分量
dlx=0;dly=y2-y1;dlz=z2-z1; %计算环各段矢量d1的3个分量,x1=x2=0
NGx=Nh;NGy=NGx; %确定网格线数
for i=1:NGx
rx=x(j)-xc,ry=y(i)-yc,rz=0-zc; %计算矢径r的3个长度分量,P点z=0
r3=sqrt(rx.^2+ry.^2+rz.^2).^3; %计算r^3
dlXr_x=dly.*rz-dlz.*ry; %计算叉乘积dl×r的x和y分量,z分量为0
dlXr_y=dlz.*rx-dlx.*rz;
Bx(i,j)=sum(C0*dlXr_x./r3); %把环各段产生的磁场分量累加
By(i,j)=sum(C0*dlXr_y./r3);
B=(Bx.^2+By.^2).^0.5; %计算B的大小
end
subplot(1,2,1),quiver(x,y,Bx,By); %用quiver画磁场矢量图
xlabel('x'),ylabel('y')
axis([-3,3,-3,3])
subplot(1,2,2)
mesh(x,y,B); %画磁场大小分布图
xlabel('x'),ylabel('y'),zlabel('v')
————————————————————————————————————————————
Subscript indices must either be real positive integers or logicals.
Error in ==> dianci at 19
rx=x(j)-xc,ry=y(i)-yc,rz=0-zc; %计算矢径r的3个长度分量,P点z=0
请问错在了那里?在十九行以下还出现什么错误了吗?
这个错误是说:
角标不能是正整数或逻辑变量
由于你的循环变量是i
而你下面的循环又用j
rx=x(j)-xc
这句应当是
rx=x(i)-xc %j改成i
再问: 那23行 24行出现了什么错误?运行之后是同样的错误 ??? Subscript indices must either be real positive integers or logicals. Error in ==> dianci at 23 Bx(i,j)=sum(C0*dlXr_x./r3); %把环各段产生的磁场分量累加
再答: 看来不是简单的打错字的问题. 你的代码好像漏掉了一个j的循环. 至于哪里漏了.现在很不好说. 你最好找一下原代码的出处.
角标不能是正整数或逻辑变量
由于你的循环变量是i
而你下面的循环又用j
rx=x(j)-xc
这句应当是
rx=x(i)-xc %j改成i
再问: 那23行 24行出现了什么错误?运行之后是同样的错误 ??? Subscript indices must either be real positive integers or logicals. Error in ==> dianci at 23 Bx(i,j)=sum(C0*dlXr_x./r3); %把环各段产生的磁场分量累加
再答: 看来不是简单的打错字的问题. 你的代码好像漏掉了一个j的循环. 至于哪里漏了.现在很不好说. 你最好找一下原代码的出处.
matlab 出现Subscript indices must either be real positive inte
MATLAB出现?Subscript indices must either be real positive inte
MATLAB里出现Subscript indices must either be real positive inte
matlab出现? Subscript indices must either be real positive int
之后的运行又出现:Subscript indices must either be real positive inte
matlab :Subscript indices must either be real positive integ
用matlab图像配准中出现Subscript indices must either be real positive
问一下在matlab中出现Subscript indices must either be real positive
matlab为什么出现 Subscript indices must either be real positive i
? Subscript indices must either be real positive integers or
Subscript indices must either be real positive integers or l
MATLAB程序错误?Subscript indices must either be real positive in