I'm pretty new using Matlab, im not sure why there's an error at line number 2. It says( Error in ==> Asys at 3 switch flag,;). I'm not sure why this error occurring. Thanks in advance. Syah.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
function [sys,x0,str,ts] = Asys (t,x,u,flag)
switch flag,;
case 0
[sys,x0,str,ts] = mdlInitializeSizes;
case 3
sys = mdlOutputs(t,x,u);
case{1,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 = 3;
sizes.NumInputs = 5;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes (sizes);
str = [];
x0 = [];
ts = [-1 0];
function sys = mdlOutputs (t,x,u)
P = sys(3) - sys(4);
if (sys(5) >= 0.3);
if (sys(4) >= sys(3))
u(1) = 0;
u(2) = sys(4);
u(3) = 0;
else
if ((sys(2) >= 0.3));
if (sys(1) >= sys(3))
u(1) = P;
u(2) = sys(4);
u(3) = 0;
else
u(1) = 0;
u(2) = 0;
u(3) = sys(3);
end
else
u(1) = 0;
u(2) = 0;
u(3) = sys(3);
end
end
else
u(1) = 0;
u(2) = 0;
u(3) = sys(3);
end
sys = u;
1 comentario
Respuestas (1)
Image Analyst
el 26 de Mayo de 2013
Why is there a comma and semi colon after the switch? Get rid of them.
8 comentarios
Walter Roberson
el 28 de Mayo de 2013
How are you executing the code? If you are selecting Run from the menu or pressing the Run button, then that will execute the code with no parameters. You need to call the code from other code, or you need to call it from the command line with appropriate parameters defined. The code is designed to be called from Simulink; is that how you are executing it?
Abioye Samson
el 28 de Mayo de 2013
call the function in a script m file instead of running it directly and supply the actual values of the input parameters
e.g
[sys,x0,str,ts] = Asys (10,2,4,3)
i.e
t=10,x=2,u=4,flag=3
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!