Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: checking a function handle
Date: Sat, 31 Oct 2009 17:12:02 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 39
Message-ID: <hchr52$ig6$1@fred.mathworks.com>
References: <8e3b51f4-f830-42f3-ab71-3a7b97a643d6@p35g2000yqh.googlegroups.com> <MPG.2554c7f35cb14522989a5a@news.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257009122 18950 172.30.248.37 (31 Oct 2009 17:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 31 Oct 2009 17:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: news.mathworks.com comp.soft-sys.matlab:581510


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