switch flag error

1 view (last 30 days)
Gabriel
Gabriel on 10 Dec 2011
Commented: muhammad ghufran on 29 Sep 2021
I am trying to find out why is this an error if it came out from a book. The m-file should be saved as a function or script please see code:
function [sys,x0,str,ts] = s_anm81s(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=md1InitializeSizes;
case 2,
sys=md1Update(t,x,u);
case 3,
sys=md1Outputs(t,x,u);
case 9,
sys=md1Terminate(t,x,u);
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=md1InitializeSizes()
sizes = simsizes;
sizes.NumContStates=0;
sizes.NumDiscStates=0;
sizes.NumOutputs=0;
sizes.NumInputs=1;
sizes.DirFeedthrough=0;
sizes.NumSampleTimes=1;
sys=simsizes(sizes);
x0=[];
str=[];
ts=[0.25 0];
if(isempty(findobj('UserData',gcb)))
h_fig=figure('Position', [200 200 400 300],...
'MenuBar','none','NumberTitle','off',...
'Resize', 'off',...
'Name', ([gcs,'RollingDisk']));
set(h_fig,'UserData',gcb);
set(h_fig,'DoubleBuffer','on');
r=2;
R=12;
q=r;
thp=0:0.2:pi;
xp=R*cos(thp);
yp=-R*sin(thp);
xp=[xp,-R,-(R+q),-(R+q),(R+q),(R+q),R];
yp=[yp,0,0,-(R+q),-(R+q),0,0];
cl_x=[0,0];
cl_y=[0,-R];
thp=0:0.3:2.3*pi;
xd=r*cos(thp);
yd=r*sin(thp);
hd=fill(xp,yp,[0.85,0.85,0.85]);
hold on;
set(hd,'EraseMode','none');
axis('equal');axis('off');
hd0=plot(cl_x,cl_y,'k--');
set(hd0,'EraseMode','none');
theta=0;
xc=(R-r)*sin(theta);
yc=-(R-r)*cos(theta);
psi=theta*(R-r)/r;
xm_c=r*sin(psi);
ym_c=r*cos(psi);
xm=xc+xm_c;
ym=yc+ym_c;
hd2=fill(xd+xc,yd+yc,[0.85,0.85,0.85]);
hd3=plot([xc,xm],[yc,ym],'k');
set_param(gcb,'UserData',[hd2,hd3]);
end
function sys=md1Update(t,x,u)
sys=[];
r=2;
R=12;
q=r;
userdat=get_param(gcb,'UserData');
hd2=userdat(1);
hd3=userdat(2);
theta=u(1);
xc=(R-r)*sin(theta);
yc=-(R-r)*cos(theta);
psi=theta*(R-r)/r;
xm_c=r*sin(psi);
ym_c=r*cos(psi);
xm=xc+xm_c;
ym=yc+ym_c;
thp=0:0.3:2*pi;
xd=r*cos(thp);
yd=r*sin(thp);
set(hd2,'XData',xd+xc);
set(hd2,'YData',yd+yc);
set(hd3,'XData',[xc, xm]);
set(hd3,'YData',[yc,ym]);
function sys=md1Outputs(t,x,u)
sys=[];
function sys=md1Terminate(t,x,u)
sys=[];
[EDITED, 12-Dec-2011 14:01 UTC, Jan Simon]: Code formatted
  5 Comments
Jan
Jan on 10 Dec 2011
Which error do you get - please copy the complete message? How do you call this funtion?
muhammad ghufran
muhammad ghufran on 29 Sep 2021
@Jan I am facing same issue like error come "Switch flag" how can I solve this error please guide me

Sign in to comment.

Answers (0)

Categories

Find more on Control System Toolbox 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!