微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

配置 S-Function 的输出

如何解决配置 S-Function 的输出

我在 Matlab 中有以下代码

function dx=massamola(t,x,u)
m=1;
k=1;
b=1;
x1 = x(1);
x2 = x(2);
dx1 = x(2);
dx2 = -(k/m)*x1-(b/m)*x2+(1/m)*u;
dx=[dx1;dx2];

在我获得 S-Function 的特定代码之后不久。

function [sys,x0,str,ts]=massamola_sfcn(t,u,flag,x10,x20)
switch flag
    case 0      %initialization
        str=[];
        ts = [0 0];
        s = simsizes;
            s.NumContStates=2;
            s.NumdiscStates=0;
            s.NumOutputs=3;
            s.NumInputs=1;
            s.DirFeedthrough=0;
            s.NumSampleTimes=1;
         sys = simsizes(s);
         x0 = [x10;x20];
    case 1      %derivatives computation
            ;
        sys = massamola(t,u);
    case 3          %output
        sys(1) = x(1); %position
        sys(2) = x(2);

    case {2 4 9}    %2:discrete
                    %4:calctimeHit
                    %9:termination
        sys = [];
    otherwise
        error(['unhandled flag=',num2str(flag)]);
end

在上面代码中看到的情况 3 中,我通过状态 x(1) 和状态位置 x(2) 的导数将质量的位置提取到 Simulink。如下图:

enter image description here

我想通过S-Function将系统对单元步长的响应提取到Simulink,如图:

enter image description here

下图是Simulink中的系统系统图:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。