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 (최근 30일)
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개)

Image Analyst
Image Analyst 2013년 5월 26일
Why is there a comma and semi colon after the switch? Get rid of them.
  댓글 수: 8
Walter Roberson
Walter Roberson 2013년 5월 28일
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 2013년 5월 28일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sparse State-Space Models에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by