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$>
References: <guh57c$9ko$> <guh9jn$1bk$> <guhae5$q3e$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1242320043 16956 (14 May 2009 16:54:03 GMT)
NNTP-Posting-Date: Thu, 14 May 2009 16:54:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1413953
Xref: comp.soft-sys.matlab:539994

"John D'Errico" <> 
<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,