Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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: 17,944
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" <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 = .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
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.