Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Is FEVAL slow?

Subject: Is FEVAL slow?

From: Chuck37

Date: 10 Aug, 2011 16:10:27

Message: 1 of 4

I'm working on something where using FEVAL seems like the most elegant way to do the implementation, but it is running very slowly and I'm wondering if FEVAL is the bottleneck. I'm doing an optimization problem with different measurement types and it's really slick to be able to add new measurement types by simply including in the measurement structure the name of the function that can generate a predicted measurement as a function of the state. The alternative is to modify the base code with case statements (or something like that) every time a new measurement type is used. I'll do that if I have to. Thanks.

Subject: Is FEVAL slow?

From: Steven_Lord

Date: 10 Aug, 2011 17:31:08

Message: 2 of 4



"Chuck37 " <chuck3737@yahooremovethis.com> wrote in message
news:j1uahj$cfl$1@newscl01ah.mathworks.com...
> I'm working on something where using FEVAL seems like the most elegant way
> to do the implementation, but it is running very slowly and I'm wondering
> if FEVAL is the bottleneck. I'm doing an optimization problem with
> different measurement types and it's really slick to be able to add new
> measurement types by simply including in the measurement structure the
> name of the function that can generate a predicted measurement as a
> function of the state. The alternative is to modify the base code with
> case statements (or something like that) every time a new measurement type
> is used. I'll do that if I have to. Thanks.

If I understand what you're doing correctly, you don't need to use FEVAL.
Use function handles.

myfunctions = struct('sin', @sin, 'blah', @cos);
x = 0:0.1:2*pi;
plot(x, myfunctions.sin(x), 'ko-', x, myfunctions.blah(x), 'b+-.')

I included blah in myfunctions just to indicate that the name of the struct
field and the function handle you store in that field don't need to be the
same.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Is FEVAL slow?

From: Bruno Luong

Date: 10 Aug, 2011 18:29:28

Message: 3 of 4

IMO any function calling in Matlab is already too slow.

Bruno

Subject: Is FEVAL slow?

From: TideMan

Date: 10 Aug, 2011 20:12:52

Message: 4 of 4

On Aug 11, 5:31 am, "Steven_Lord" <sl...@mathworks.com> wrote:
> "Chuck37 " <chuck3...@yahooremovethis.com> wrote in message
>
> news:j1uahj$cfl$1@newscl01ah.mathworks.com...
>
> > I'm working on something where using FEVAL seems like the most elegant way
> > to do the implementation, but it is running very slowly and I'm wondering
> > if FEVAL is the bottleneck.  I'm doing an optimization problem with
> > different measurement types and it's really slick to be able to add new
> > measurement types by simply including in the measurement structure the
> > name of the function that can generate a predicted measurement as a
> > function of the state.  The alternative is to modify the base code with
> > case statements (or something like that) every time a new measurement type
> > is used.  I'll do that if I have to.  Thanks.
>
> If I understand what you're doing correctly, you don't need to use FEVAL.
> Use function handles.
>
> myfunctions = struct('sin', @sin, 'blah', @cos);
> x = 0:0.1:2*pi;
> plot(x, myfunctions.sin(x), 'ko-', x, myfunctions.blah(x), 'b+-.')
>
> I included blah in myfunctions just to indicate that the name of the struct
> field and the function handle you store in that field don't need to be the
> same.
>
> --
> Steve Lord
> sl...@mathworks.com
> To contact Technical Support use the Contact Us link onhttp://www.mathworks.com

And, if you want to use a variable function name, just enclose it in
parentheses:
myfun='blah';

plot(x, myfunctions.sin(x), 'ko-', x, myfunctions.(myfun)(x), 'b+-.')

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us