Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Error in (embedded) MATLAB function
Posted:
Feb 13, 2013 9:17 AM


"Hamid Mazaheri" <chub_kebreet@yahoo.com> wrote in message news:kfg5gq$74i$1@newscl01ah.mathworks.com... > I have a problem using (embedded) MATLAB functions. > I have this code: > > function [y1,y2]= fcn(u1,u2,u3) > %#codegen > Ts = .1e3; > persistent l % ia an auxiliary variable > if isempty(l) > l = 0; > end > persistent x1 % x1 is first state variable > if isempty(x1) > x1 = 0; > end > persistent x2 % x2 is second state variable > if isempty(x2) > x2 = 0; > end > if floor(u3/Ts) >= l > l = l+1; > y1 = .3067*x1+3.5924*x2+.6933*u13.5994*u2; > y2 = .2515*x1+.3042*x2+.2515*u1+.6933*u2; > x1 = y1; > x2 = y2; > end > > The system has two inputs and two outputs. > Running the system gives the following error: > > Output argument 'y1' is not assigned on some execution paths. > Function 'MATLAB Function' (#22.18.21), line 1, column 19: > "fcn"
What happens if floor(u3/Ts) is strictly less than l? [BTW, please choose a different variable name for this auxiliary variable; lowercase L's, uppercase i's, and the number 1 can be difficult to distinguish in many fonts.] Your last IF block never executes. What value should the first output of the function have in that case? It doesn't have one with your function as written, and that's the cause of the error.
 Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com



