Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: subfunctions versus overloaded functions
Date: Thu, 14 May 2009 16:54:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <guhibb$ghs$1@fred.mathworks.com>
References: <guh57c$9ko$1@fred.mathworks.com> <guh9jn$1bk$1@fred.mathworks.com> <guhae5$q3e$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242320043 16956 172.30.248.38 (14 May 2009 16:54:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 14 May 2009 16:54:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1413953
Xref: news.mathworks.com comp.soft-sys.matlab:539994

"John D'Errico" <woodchips@rochester.rr.com> 
<wants to  execute a function shadowed by a subfunction />

I've had this problem in the past, too.  I thought a simple solution would be to create a function handle to the specific instance of a shadowed function using relative path notation, i.e., in your case:

fun = @specfun\isprime;  %or
fun = str2func('specfun\isprime');

But, it doesn't work.

I'm not sure how to circumvent the precedence of a subfunction.  If you are simply trying to access a function that is shadowed by some other function on the path (not a subfunction) a solution is to parse the output of "which -all filename" for the location of the shadowed function, change directory so that the shadowed version has precedence on the path, create the function handle, and change directory back.

Is it a disaster to make the subfunction stand on its own as opposed to being included in the main function?  You could then execute whichever version you wished either by manually checking the type yourself (which you indicate you'd like to avoid) or let MATLAB's dispatching rules for overloaded functions do the work.

Hope that's helpful,

CD