switch flag error

1 vue (au cours des 30 derniers jours)
Gabriel
Gabriel le 10 Déc 2011
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 commentaires
Jan
Jan le 10 Déc 2011
Which error do you get - please copy the complete message? How do you call this funtion?
muhammad ghufran
muhammad ghufran le 29 Sep 2021
@Jan I am facing same issue like error come "Switch flag" how can I solve this error please guide me

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Control System Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by