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

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
str2func Dave Brackett 15 Jun, 2009 15:12:33
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com