Error in 'Project_complete_try/Vehicle Dynamics/Longitudinal State Space Matrix' while executing MATLAB S-function 'ss_lon_sfcn', flag = 1 (derivatives), at time 0.0.
Show older comments
function [sys,x0,str,ts]=ss_lon_sfcn(t,x,u,flag,xinit)
switch flag
case 0 % initialize
str=[] ;
ts = [0 0] ;
s = simsizes ;
s.NumContStates = 4 ;
s.NumDiscStates = 0 ;
s.NumOutputs = 4 ;
s.NumInputs = 1 ;
s.DirFeedthrough = 0 ;
s.NumSampleTimes = 1 ;
sys = simsizes(s) ;
x0 = xinit ;
case 1 % derivatives
sys = ss_lon(t,x,u) ;
case 3 % output
sys = x;
case {2 4 9}
% 2:discrete
% 4:calcTimeHit
% 9:termination
sys =[];
otherwise
error(['unhandled flag =',num2str(flag)]) ;
end
where the function is as:
function lon_dynamics = ss_lon(t,x,u)
if t>=0 && t<1
A_MATRIX = evalin('base', 'A_MATRIX:,:,1)');
B_MATRIX = evalin('base', 'B_MATRIX:,:,1)');
elseif t>=1 && t<2
A_MATRIX = evalin('base', 'A_MATRIX:,:,1)');
B_MATRIX = evalin('base', 'B_MATRIX:,:,1)');
elseif t>=2 && t<3
A_MATRIX = evalin('base', 'A_MATRIX:,:,2)');
B_MATRIX = evalin('base', 'B_MATRIX:,:,2)');
elseif t>=3 && t<4
A_MATRIX = evalin('base', 'A_MATRIX:,:,3)');
B_MATRIX = evalin('base', 'B_MATRIX:,:,3)');
end
lon_dynamics = A_MATRIX*x+B_MATRIX*u;
end
Answers (0)
Categories
Find more on Signal Analysis 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!