The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Error in (embedded) MATLAB function
Replies: 3   Last Post: Feb 15, 2013 12:59 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Error in (embedded) MATLAB function
Posted: Feb 13, 2013 9:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Hamid Mazaheri" <> wrote in message
> 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.

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.