声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3181|回复: 1

[编程技巧] 求助:老问题Undefined function or variable 't'

[复制链接]
发表于 2009-2-26 16:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我编的一个s函数中,在指向machine.m 文件时,弹出对话框 Error in '' while executing M-files S-function 'machine', flag = 0(initialize), at start of  simulation. MATLAB error message: Undefined function or variable 't'.

我这个s函数里面没有用到变量't'啊,而且这个t是s函数里面function [sys,x0,str,ts]=machine(t,x,u,flag,p,Rs,Rr,Ls,Lr,Lm,J,w1)自带的呀
我也搜索了其它帖子,还有置顶帖,小弟不才,还是没有搞定。下面是整个s函数,麻烦帮我看看。。非常感谢~

%S-function for continuous state equation
function [sys,x0,str,ts]=machine(t,x,u,flag,p,Rs,Rr,Ls,Lr,Lm,J,w1)
%定义参数吧
p=2;  Rs= 0.435; Rr=0.816 ; Ls=71.31;Lr=71.31; Lm=69.31; J=0.089; w1=120*pi;
switch flag,
%Initialization
  case 0,
    [sys,x0,str,ts]=mdlInitializeSizes(p,Rs,Rr,Ls,Lr,Lm,J,w1);
  case 1
    sys=mdlDerivatives(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1);
%Outputs
  case 3,
    sys=mdlOutputs(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1);
%Unhandled flags
  case {2, 4, 9 }
    sys = [];
%Unexpected flags
  otherwise
    error(['Unhandled flag = ',num2str(flag)]);
end
%mdlInitializeSizes
function [sys,x0,str,ts]=mdlInitializeSizes(p,Rs,Rr,Ls,Lr,Lm,J,w1)
sizes = simsizes;
sizes.NumContStates  = 5;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 6;
sizes.NumInputs      = 5;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys=simsizes(sizes);
x0=[0 0 0 0 0];
str=[];
ts=[0 0];
sys=mdlDerivatives(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1);
% x=[ids iqs idr iqr wr];u=[uds uqs udr uqr Tm];
Ll=Ls*Lr-Lm^2;
bn=1.5*p^2*Lm*Ll/J;
A=1/Ll*[-Rs*Lr               w1*Ll+x(5)*Lm^2     Rr*Lm        x(5)*Lr*Lm        0;
        -w1*Ll-x(5)*Lm^2      -Rs*Lr          -x(5)*Lr*Lm      Rr*Lm            0;
        Rs*Lm                -x(5)*Ls*Lm       -Rs*Lr        w1*Ll-x(5)*Ls*Lr   0;
        x(5)*Ls*Lm             Rs*Lr        -w1*Ll+x(5)*Ls*Lr    -Rs*Lr         0;
        -bn*x(4)            bn*x(3)             0                   0           0; ]
B=1/Ll*[Lr 0  -Lm 0 0;
        0  Lr  0  -Lm 0
        -Lm 0 Ls 0 0
        0 -Lm 0 Ls 0
        0 0 0 0 -p*Ll/J]
sys=A*x(1:5)+B*u;
% R=[Rs 0 0 0;0 Rs 0 0;0 wLm Rr wLr;-wLm 0 -wLr Rr];
% sys=-L*R*x+L*U;
function sys=mdlOutputs(t,x,u,p,Rs,Rr,Ls,Lr,Lm,J,w1)
x(6)=1.5*p*Lm*(x(3)*x(2)-x(1)*x(4));
sys=x;
% sys(1)=u(1);
% sys(2)=x(1);
% sys(3)=u(2);
% sys(4)=x(2);
% sys(5)=1.5*Pn*Lm*(x(2)*x(3)-x(1)*x(4));
回复
分享到:

使用道具 举报

发表于 2009-2-28 10:37 | 显示全部楼层
初始化肯定要有时间 这些函数不要改动
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-6-9 23:32 , Processed in 0.057439 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表