"Hamid Mazaheri" <firstname.lastname@example.org> wrote in message news:email@example.com... > I have a problem using (embedded) MATLAB functions. > I have this code: > > function [y1,y2]= fcn(u1,u2,u3) > %#codegen > Ts = .1e-3; > 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*u1-3.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; lower-case L's, upper-case 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.