Sizes vector returned by MATLAB S-function

4 views (last 30 days)
After I compile this S-function:
function [sys,x0,str,ts] = Derivative1(t,x,u,flag)
global n;
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(n);
case 3,
sys=mdlOutputs(t,x,u,n);
case {1,2,4,9}
sys=[];
otherwise
error (['Unhandled flag= ',num2str(flag)]);
end
function [sys,x0,str,ts] =mdlInitializeSizes(n)
global sample_time
sizes=simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = n;
sizes.NumInputs = -1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts= [sample_time 0];
function sys=mdlOutputs(t,x,u,n)
global sample_time
z=0;
for i=1:(n-1)
if (t>=sample_time*i)
z(i)=((-1)^i)*diff(u([1:[i+1],i]),i)/(sample_time^i);
else z(i)=0;
end
end
sys=[u(1),z];
return
The compiler generates an error: Sizes vector returned by MATLAB S-function 'Derivative1' in 'Adaptive_Controller/Adaptive Controller /Derivative1' must be a real vector consisting of integer value of length 7 Please tell me what I do wrong. Thank you in advance.

Answers (0)

Categories

Find more on Block and Blockset Authoring 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!