MATLAB Answers

batista1987
0

S-function error: not enough input arguments

Asked by batista1987
on 28 Dec 2011

hi guys when i try to use the follow s-function in a simulink blocket, i obtain this error: Error in S-function while executing Matlab s-function 'sist_nn_lin' flag = 0 (initialize), at start of simulation. -->Not enough input arguments

This is the function code:

function [sys,x0,str,ts] = sist_nn_lin(t,x,u,flag,Cout,angInit)
switch flag
    case 0, % initialize
        s = simsizes;
        s.NumContStates = 4;
        s.NumDiscStates = 0;
        dimOut = size(Cout);
        s.NumOutputs = dimOut(1);
        s.NumInputs = 1;
        s.DirFeedthrough = 0;
        s.NumSampleTimes = 1;
        sys = simsizes(s);
        x0 = [0; 0; angInit; 0];
        str=[];
        ts = [0 0];
    case 1, % derivatives
        m = 0.17
        M = 0.238; 
        l = 0.1; 
        g = 9.81;
    x1 = x(1); %positions
        x2 = x(2); %speed
        x3 = x(3); %angle
        x4 = x(4); %angular speed
        sum = (M + m*(sin(x3))^2);
        F_in = u;
        dx1 = x2;
        dx2 = ( +m*l*((x4)^2)*sin(x3) - m*g*sin(x3)*cos(x3) + F_in ) / sum;
        dx3 = x4;
        dx4 = ( -m*l*((x4)^2)*sin(x3)*cos(x3) + (M+m)*g*sin(x3) - F_in*cos(x3) ) / (l*sum);
        sys = [dx1;dx2;dx3;dx4];
      case 3, % output
          sys = Cout*x;
      case {2 4 9},
          % 2:discrete 4:calcTimeHit 9:termination
          sys =[];
      otherwise
          error(['Error - unhandled flag =',num2str(flag)]) ;
  end

  0 Comments

2 Answers

Answer by Kaustubha Govind
on 28 Dec 2011

Have you set the S-function parameters field in the block dialog window to "Cout,angInit" (without the quotes)?

  0 Comments


Answer by batista1987
on 28 Dec 2011

no...What should I write in parameters fied? And how initialize this parameters?

  1 Comment

Write "Cout,angInit" (without the quotes). Define Cout and angInit in the MATLAB workspace.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!