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: 2   Last Post: Feb 16, 2013 11:03 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Phil Goddard

Posts: 351
Registered: 1/27/12
Re: Error in (embedded) MATLAB function
Posted: Feb 16, 2013 11:03 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

It's a bit unrealistic to ask for comments on the format of code that doesn't execute as it will obviously have to change for it to actually run.

In general you don't need to check whether all of your persistent variables are empty -- if one is empty they all will be, so

> if isempty(m)
> m = 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


becomes

if isempty(m)
m = 0;
x1 = 0;
x2 = 0;
end

But in your latest version x1 and x2 aren't defined as being persistent so this will error out saying they are undefined.
Also in your latest version you are (trying) to pass a string input to the 'test' function, but 'test' hasn't been written to accept any inputs.

If you do (in your final version which you haven't told us anything about) want/need to call an external function then you have used extrinsic definition correctly.

For what you have shown, I'd go back to your original version and have some persistent variables -- something like y1p and y2p -- then have

if floor(u3/Ts) >= l
l = l+1;
y1p = .3067*x1+3.5924*x2+.6933*u1-3.5994*u2;
y2p = -.2515*x1+.3042*x2+.2515*u1+.6933*u2;
x1 = y1p;
x2 = y2p;
end
y1 = y1p;
y2 = y2p;

In that way y1 and y2 are defined every time the function is called, but their value only changes when the sample time is hit.

Phil.



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.