In article <8e3b51f4-f830-42f3-ab71-3a7b97a643d6
@p35g2000yqh.googlegroups.com>, msmscarlatti@googlemail.com says...
> I want to check in an if statement if a function handle is equal to
> the identity @(x) 1. Is there any way for me to do that?
>
> Thanks.
>
I'll show you how (with an undocumented function), but why do you want
to check this? What if the user writes the identity as @(x) ones(1), or
any other number of ways. This seems possibly ill-conceived.
You could use functions on the fh, and then get the function expression
from there.
x = @(q) 1
s = functions(x)
x =
@(q)1
s =
function: '@(q)1'
type: 'anonymous'
file: ''
workspace: {[1x1 struct]}
>> s.function
ans =
@(q)1
Loren Shure <loren.shure@mathworks.com> wrote in message <MPG.2554c7f35cb14522989a5a@news.mathworks.com>...
> In article <8e3b51f4-f830-42f3-ab71-3a7b97a643d6
> @p35g2000yqh.googlegroups.com>, msmscarlatti@googlemail.com says...
> > I want to check in an if statement if a function handle is equal to
> > the identity @(x) 1. Is there any way for me to do that?
> >
> > Thanks.
> >
>
> I'll show you how (with an undocumented function), but why do you want
> to check this? What if the user writes the identity as @(x) ones(1), or
> any other number of ways. This seems possibly ill-conceived.
>
> You could use functions on the fh, and then get the function expression
> from there.
>
> x = @(q) 1
> s = functions(x)
> x =
> @(q)1
> s =
> function: '@(q)1'
> type: 'anonymous'
> file: ''
> workspace: {[1x1 struct]}
> >> s.function
> ans =
> @(q)1
>
> --
> Loren
> http://blogs.mathworks.com/loren
Actually, Loren, I believe that @functions is an entirely-documented function: it has both a help section (%matlabroot%\toolbox\matlab\datatypes\functions.m) and a doc-page. It even appears in the online version: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/functions.html . Perhaps it was undocumented in some old release, but it's documented at least since R2008a.
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.