|
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.
Yair Altman
http://UndocumentedMatlab.com
|