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.

4 Ansichten (letzte 30 Tage)
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;

Antworten (1)

Image Analyst
Image Analyst am 26 Mai 2013
Why is there a comma and semi colon after the switch? Get rid of them.
  8 Kommentare
Walter Roberson
Walter Roberson am 28 Mai 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
Abioye Samson am 28 Mai 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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by