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:
str2func with cell input arguments

Subject: str2func with cell input arguments

From: Dave Brackett

Date: 15 Jun, 2009 19:08:02

Message: 1 of 2

Up until recently I have been using str2func for specifying some options for an optimisation run. With r2009a this is no longer allowed and I get the error message: "??? Undefined function or method 'str2func' for input arguments of type 'cell'."

This worked fine in 2008a and I read from Loren's blog that there have been some changes to str2func in the latest release (Starting in Release 2009a, str2func lets you create a handle to anonymous function. Before that, you need to construct an anonymous function from literal strings, or using some ugly code involving eval.).

I cannot work out what I need to change to get it to work in my case. Can anyone shed some light on what I'm missing please? Thanks. A snippet of the code is below:
 
   options=saoptimset('AnnealingFcn',str2func(current_options.annealing_function),...
            'TemperatureFcn',str2func(current_options.temperature_function),...
            'AcceptanceFcn',str2func(current_options.acceptance_function));

Subject: str2func with cell input arguments

From: Dave Brackett

Date: 15 Jun, 2009 19:20:18

Message: 2 of 2

"Dave Brackett" <davebrackett@hotmail.com> wrote in message <h1666i$8n9$1@fred.mathworks.com>...
> Up until recently I have been using str2func for specifying some options for an optimisation run. With r2009a this is no longer allowed and I get the error message: "??? Undefined function or method 'str2func' for input arguments of type 'cell'."
>
> This worked fine in 2008a and I read from Loren's blog that there have been some changes to str2func in the latest release (Starting in Release 2009a, str2func lets you create a handle to anonymous function. Before that, you need to construct an anonymous function from literal strings, or using some ugly code involving eval.).
>
> I cannot work out what I need to change to get it to work in my case. Can anyone shed some light on what I'm missing please? Thanks. A snippet of the code is below:
>
> options=saoptimset('AnnealingFcn',str2func(current_options.annealing_function),...
> 'TemperatureFcn',str2func(current_options.temperature_function),...
> 'AcceptanceFcn',str2func(current_options.acceptance_function));



ah isn't it always the way that as soon as you post the question, you work out the answer! Simply just needs to use char() to convert from cell. Funny I didn't think of that earlier!

Tags for 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