请教Matlab关于S函数多输入和多输出的问题
要编写一个s函数,有两个输入,三个输出,输入为参考电流Is和电角度angle,输出为三相电流Ia,Ib,Ic,问:1、函数的外部使用MUX模块将Is和angle连接起来一...
要编写一个s函数,有两个输入,三个输出,输入为参考电流Is和电角度angle,输出为三相电流Ia,Ib,Ic,问:
1、函数的外部使用MUX模块将Is和angle连接起来一同接入s-function函数模块吗?
2、此函数的s-function parameter怎么设置?(Is和angle外部的子系统计算结果给定)
3、对于函数程序中的所涉及的五个参数如何声明?(我的这个老说我没定义Is)
function [sys,x0,str,ts] = test_0105(t,x,u,flag,Is,angle)
switch flag,
case 0,
[sys,x0,str,ts,Ia,Ib,Ic]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,Is,angle);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts,Ia,Ib,Ic]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
function [Ia,Ib,Ic]=mdlOutputs(t,x,u,Is,angle)
pos=angle-floor(angle/2/pi)*2*pi;
if pos<pi/3
Ia=Is;Ib=-Is;Ic=0;
elseif pos<2*pi/3
Ia=Is;Ib=0;Ic=-Is;
elseif pos<pi
Ia=0;Ib=Is;Ic=-Is;
elseif pos<4*pi/3
Ia=-Is;Ib=Is;Ic=0;
elseif pos<5*pi/3
Ia=-Is;Ib=0;Ic=Is;
else
Ia=0;Ib=-Is;Ic=Is;
end 展开
1、函数的外部使用MUX模块将Is和angle连接起来一同接入s-function函数模块吗?
2、此函数的s-function parameter怎么设置?(Is和angle外部的子系统计算结果给定)
3、对于函数程序中的所涉及的五个参数如何声明?(我的这个老说我没定义Is)
function [sys,x0,str,ts] = test_0105(t,x,u,flag,Is,angle)
switch flag,
case 0,
[sys,x0,str,ts,Ia,Ib,Ic]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u,Is,angle);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts,Ia,Ib,Ic]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
function [Ia,Ib,Ic]=mdlOutputs(t,x,u,Is,angle)
pos=angle-floor(angle/2/pi)*2*pi;
if pos<pi/3
Ia=Is;Ib=-Is;Ic=0;
elseif pos<2*pi/3
Ia=Is;Ib=0;Ic=-Is;
elseif pos<pi
Ia=0;Ib=Is;Ic=-Is;
elseif pos<4*pi/3
Ia=-Is;Ib=Is;Ic=0;
elseif pos<5*pi/3
Ia=-Is;Ib=0;Ic=Is;
else
Ia=0;Ib=-Is;Ic=Is;
end 展开
1个回答
展开全部
问题太多,就不用一一指正了,以下程序已经经过调试成氏正功。
function [sys,x0,str,ts] = test_0105(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9},
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [];
function sys=mdlOutputs(t,x,u)
Is=u(1);angle=u(2);
pos=rem(angle,2*pi);
if pos<pi/3
Ia=Is;Ib=-Is;Ic=0;
elseif pos<2*pi/3
Ia=Is;Ib=0;Ic=-Is;
elseif pos<pi
Ia=0;Ib=Is;Ic=-Is;
elseif pos<4*pi/3
Ia=-Is;Ib=Is;Ic=0;
elseif pos<5*pi/3
Ia=-Is;Ib=0;Ic=Is;
else
Ia=0;Ib=-Is;Ic=Is;
end
sys=[Ia Ib Ic];
问题回答改兆:
1.是的
2.Is和angle已经通过mux模块集中传送给s-function,不需要通过s-function parameter赋值。在程序里面用u(1) u(2)就可以得到输入的值
3.你的程序都是从外部计算之后送给s-function的,不用定义参数。核核租
function [sys,x0,str,ts] = test_0105(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9},
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [];
function sys=mdlOutputs(t,x,u)
Is=u(1);angle=u(2);
pos=rem(angle,2*pi);
if pos<pi/3
Ia=Is;Ib=-Is;Ic=0;
elseif pos<2*pi/3
Ia=Is;Ib=0;Ic=-Is;
elseif pos<pi
Ia=0;Ib=Is;Ic=-Is;
elseif pos<4*pi/3
Ia=-Is;Ib=Is;Ic=0;
elseif pos<5*pi/3
Ia=-Is;Ib=0;Ic=Is;
else
Ia=0;Ib=-Is;Ic=Is;
end
sys=[Ia Ib Ic];
问题回答改兆:
1.是的
2.Is和angle已经通过mux模块集中传送给s-function,不需要通过s-function parameter赋值。在程序里面用u(1) u(2)就可以得到输入的值
3.你的程序都是从外部计算之后送给s-function的,不用定义参数。核核租
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询