Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2009-05-13
帖子: 1
声望力: 0 ![]() |
![]()
matlab命令如下是可以运行的
A=[2,3;0,-1];B=[0,1;1,0];C=[1,1;0,-1];D=[1,0;1,0]; x0=[2;-1]; t=0:0.1:3; f(:,1)=ones(1, length(t)); f(:,2)=exp(-3*t); sys=ss(A,B,C,D); y=lsim(sys,f,t,x0); subplot(2,1,1);plot(t,y(:,1)); ylabel('yl(t)');xlabel('t'); grid on; subplot(2,1,2);plot(t,y(:,2)); ylabel('y2(t)');xlabel('t'); grid on; 但是若把t=0:0.1:3;语句改为t=0:0.02:3;或是改成其他的时间间隔,就出现如下错误 ??? Error using ==> unknown Subscripted assignment dimension mismatch. Error in ==> test21222 at 4 f(:,1)=ones(1,length(t)); |
![]() |
![]() |
![]() |
#2 |
初级会员
注册日期: 2009-05-11
年龄: 38
帖子: 7
声望力: 0 ![]() |
![]()
把程序改成如下的形式就可以了:
clear close all A=[2,3;0,-1];B=[0,1;1,0];C=[1,1;0,-1];D=[1,0;1,0]; x0=[2;-1]; t=0:0.02:3; f(:,1)=ones(1, length(t)); f(:,2)=exp(-3*t); sys=ss(A,B,C,D); y=lsim(sys,f,t,x0); subplot(2,1,1);plot(t,y(:,1)); ylabel('yl(t)');xlabel('t'); grid on; subplot(2,1,2);plot(t,y(:,2)); ylabel('y2(t)');xlabel('t'); grid on; 其实就是在你的程序前面加上了清理工作区和关掉多余窗口的命令。我不知道该如何解释这个问题,不过在每次程序运行前最好能清理下工作区,避免不必要的错误出现 |
![]() |
![]() |