1

I have the following codes in 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];

soon after I have a specific code of an S-Function.

function [sys,x0,str,ts]=massamola_sfcn(t,x,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,x,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

In case 3 seen in the code above, I extract to Simulink the position of the mass through state x(1) and the derivative of state position x(2). As shown below:

enter image description here

I want to extract to Simulink through the S-Function the system's response to the unit step, as shown in the figure:

enter image description here

Below is a picture of the system system in Simulink:

enter image description here

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
user13053456
  • 35
  • 1
  • 4
  • The images I don't know why the stack overflow didn't load. But why did you cross out the name Matlab? – user13053456 Jul 01 '21 at 16:26
  • Re. images: new users aren't allowed to post inline images because too many people post screenshots of text (which is not allowed). I inlined them for you after checking that they weren't screenshots of text. Re. removing "Matlab" from the title: That's the way SO's titles work. The most popular tag for the question (in this case Matlab) is added automatically to the title. You don't need to include this in your question. The edits don't imply that your question was bad or wrong, they just make your question easier to read and find. – Pranav Hosangadi Jul 01 '21 at 16:32
  • do you know anything about my question? – user13053456 Jul 01 '21 at 16:35
  • More information: [Should questions include “tags” in their titles?](https://meta.stackexchange.com/q/19190/174780) | [Embedded images for new users](https://meta.stackoverflow.com/a/307500/843953) – Pranav Hosangadi Jul 01 '21 at 16:35

0 Answers0