Path: news.mathworks.com!not-for-mail
From: "Steven_Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: subfunctions versus overloaded functions
Date: Wed, 23 Feb 2011 09:46:49 -0500
Organization: MathWorks
Lines: 68
Message-ID: <ik36kp$h1o$1@fred.mathworks.com>
References: <guh57c$9ko$1@fred.mathworks.com> <guh9jn$1bk$1@fred.mathworks.com> <guhae5$q3e$1@fred.mathworks.com> <guhibb$ghs$1@fred.mathworks.com> <guhkma$hk7$1@fred.mathworks.com> <guhpjq$8gs$1@fred.mathworks.com> <MPG.247738c679bc0ce9899af@news.mathworks.com> <ik1nt0$5qk$1@fred.mathworks.com>
NNTP-Posting-Host: ah-slord.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="UTF-8";
	reply-type=response
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1298472409 17464 172.31.44.225 (23 Feb 2011 14:46:49 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Feb 2011 14:46:49 +0000 (UTC)
In-Reply-To: <ik1nt0$5qk$1@fred.mathworks.com>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: news.mathworks.com comp.soft-sys.matlab:711862



"Mason Freed" <mfreedREMOVETHIS@mfreedREMOVETHIS.com> wrote in message 
news:ik1nt0$5qk$1@fred.mathworks.com...
> Loren Shure <loren@mathworks.com> wrote in message 
> <MPG.247738c679bc0ce9899af@news.mathworks.com>...
>>
>> Actually, since isprime is an MATLAB file and not a built in function, 
>> calling builtin in this case won't work.
>> -- 
>> Loren
>> http://blogs.mathworks.com/loren
>
> I've run into a similar problem, and came across this thread in my search 
> for a solution. My problem is that I have a CLASS that implements a method 
> called unique, to overload the standard method from toolbox\matlab\ops. 
> Inside my function, I just want to handle a couple special cases that I 
> can speed up with knowledge of the workings of my object, but leave the 
> rest of the cases to the standard unique.m. However, as mentioned, I can't 
> call builtin('unique',args) from within my overloaded class method, 
> because it just says "Cannot find builtin function 'unique'". How can I 
> call the "builtin" version of unique here? Help!

What Loren said for ISPRIME is true for UNIQUE as well.

But your version of UNIQUE is a _method_ of your object, not a subfunction, 
correct?

If you call UNIQUE and none of the inputs are instances of your class, then 
MATLAB will not call the method.  So if inside your UNIQUE method you need 
to call UNIQUE on a double array, the UNIQUE that ships with MATLAB would be 
called instead of your method.

classdef myobj
% Invoke as:
% y = myobj([1:10 1:10]);
% unique(y)
    properties
        data
    end
    methods
        function obj = myobj(x)
            obj.data = x;
        end
        function unique(obj)
            disp('Starting UNIQUE method')
            disp(unique(obj.data));
            disp('Finishing UNIQUE method')
        end
    end
end

When you use the commands given in this class's help text, you should see 
the following output:

Starting UNIQUE method
     1     2     3     4     5     6     7     8     9    10

Finishing UNIQUE method

since unique(obj.data) will NOT invoke the method again.

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com