Hello, a error has come in my s-function kindly help me....
Show older comments
error
An error occurred while running the simulation and the simulation was terminated Caused by: Error in 'untitled/S-Function' while executing MATLAB S-function 'chap1_1ctrl', flag = 3 (output), at time 0.0. Too many input arguments.
--------------------------------------------------------------------------------------------------------------------------------
function [sys, x0, str, ts]=chap1_1ctrl(t,x,u,flag)
switch flag,
case 0,
[sys, x0, str, ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u,J);
case 3,
sys=mdlOutputs(t,x,u,J);
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=1;
sizes.NumInputs=3;
sizes.DirFeedthrough=1;
sizes.NumSampleTimes=0;
sys=simsizes(sizes);
x0=[];
str=[];
ts=[];
function sys=mdlOutputs(t,x,u)
J=2;
thd=u(1);
th=u(2);
dth=u(3);
e=th-thd;
de=dth;
c=10;
s=c*e+de;
xite=1.1;
k=0;
%k=10;
ut=J*(-c*dth-1/J*(k*s+xite*sign(s)));
sys(1)=ut;
Answers (1)
Geoff Hayes
on 17 Feb 2019
Edited: Geoff Hayes
on 17 Feb 2019
Abdul - in the chap1_1ctrl function, you have the following code
case 3,
sys=mdlOutputs(t,x,u,J);
where you are passing four input parameters into the mdlDerivatives function. In the same piece of code, you have included this function
function sys=mdlOutputs(t,x,u)
which has (according to its signature) only three input parameters. I suspect that this is the source of the error too many input arguments. Either you are passing too many input parameters or this function needs to accept a fourth parameter.
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!