MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [求助]帮我看下matlab错误: index out of bounds (https://www.labfans.com/bbs/showthread.php?t=7002)

lohas1985 2009-03-22 20:01

[求助]帮我看下matlab错误: index out of bounds
 
哪位兄弟帮我看下到底哪里错了?
sym u1
m=0.0001;
t=0.03;
il=0;
i3(1)=0;
i2(1)=0;
i=1;
for x=0:m:t
ie=0.1*cos(314.16*x);
if x==0
il=0;
else
il=il+0.00033*(u1-u2(i-1));
end
if x<0.001
i2(i)=0;
i3(i)=0;
else if x<0.002
i2(i)=-0.00752*u3(i-9);
i3(i)=-0.00752*u2(i-9);
else i2(i)=-0.00752*u3(i-9)-i3(i-19);
i3(i)=-0.00752*u2(i-9)-i2(i-19);
end
end
Y=[0.100167,-0.000167,0;
-0.000167,0.003903,0;
0,0,0.003737];
U=[u1;u2(i);u3(i)];
It=[ie;
0;
0];
I=[-il;
il-i2(i);
-i3(i)];
U=inv(Y)*(It+I);
plot(double(x),double(u3(i)));
hold on
i=i+1;
end
运行后系统出现
??? Attempted to access u2(2); index out of bounds because numel(u2)=1.

Error in ==> zuoye at 28
U=[u1;u2(i);u3(i)];
是不是矩阵不能这样运算?

云龙九现 2009-03-23 10:00

回复: [求助]帮我看下matlab错误: index out of bounds
 
你u2,u3未定义,按你的意思,u2,u3也像u1一样,是一个sym变量。但你没把他们定义成这个。

laosam280 2009-03-25 17:32

回复:[求助]帮我看下matlab错误: index out of bounds
 
你把这三个u拼成一个矩阵的时候,阶数并不是一样的,所以报错了


所有时间均为北京时间。现在的时间是 14:16

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.