f



Conflict between property name and Matlab buit-in function name

I am writing some OOP code in Matlab and I wonder if there 
is any way to specific a function from the Matlab built-in 
class.

The reason why I want to do this is because I want to be 
able to use some of the Matlab built-in function names 
(such as "mean" and "kurtosis") as property names of my 
class and use the corresponding builtin function to compute 
these property values.

To illustrate my problem, I want to be able to do something 
like this:

    function value = get.mean( obj )
      value = MatlabClass.mean( obj.values ) ;
    end

Thanks for reading.
0
cf276 (23)
7/25/2008 6:57:01 AM
comp.soft-sys.matlab 211266 articles. 19 followers. lunamoonmoon (257) is leader. Post Follow

4 Replies
441 Views

Similar Articles

[PageSpeed] 57

Perhaps the Matlab-function 'builtin' is what you need:

builtin('mean', obj.values);


0
noemail10 (353)
7/25/2008 8:23:01 AM
"Eric " <noemail@noemail.com> wrote in message
<g6c2h5$f3v$1@fred.mathworks.com>...
> Perhaps the Matlab-function 'builtin' is what you need:
> 
> builtin('mean', obj.values);
> 
> 

An addition to my previous post:
The function 'mean' seems not to be a built-in function,
which means that my proposed function won't work.
(Compare the output of
which mean -all
and
which builtin -all
The latter function 'builtin' is a real built-in function.)


To get your desired behaviour, you could set the current
Matlab path to the one which contains the shadowed function
for the call:

curdir = cd(); % remember current path
cd([matlabroot '\toolbox\matlab\datafun']);
result = mean(obj.values);
cd(curdir); % "reset" path

But perhaps somebody knows a neater way.
0
noemail10 (353)
7/25/2008 11:58:36 AM
"Eric " <noemail@noemail.com> wrote in message
<g6c2h5$f3v$1@fred.mathworks.com>...
> Perhaps the Matlab-function 'builtin' is what you need:
> 
> builtin('mean', obj.values);
> 
> 

An addition to my previous post:
The function 'mean' seems not to be a built-in function,
which means that my proposed function won't work.
(Compare the output of
which mean -all
and
which builtin -all
The latter function 'builtin' is a real built-in function.)


To get your desired behaviour, you could set the current
Matlab path to the one which contains the shadowed function
for the call:

curdir = cd(); % remember current path
cd([matlabroot '\toolbox\matlab\datafun']);
result = mean(obj.values);
cd(curdir); % "reset" path

But perhaps somebody knows a neater way.
0
noemail10 (353)
7/25/2008 12:00:06 PM
In article <g6btft$odj$1@fred.mathworks.com>, cf276@hotmail.com says...
> I am writing some OOP code in Matlab and I wonder if there 
> is any way to specific a function from the Matlab built-in 
> class.
> 
> The reason why I want to do this is because I want to be 
> able to use some of the Matlab built-in function names 
> (such as "mean" and "kurtosis") as property names of my 
> class and use the corresponding builtin function to compute 
> these property values.
> 
> To illustrate my problem, I want to be able to do something 
> like this:
> 
>     function value = get.mean( obj )
>       value = MatlabClass.mean( obj.values ) ;
>     end
> 
> Thanks for reading.
> 

You should be able to call the MATLAB function.  Here's a simple 
example.

classdef foobar
    properties
        values = [1 5 7];
    end
    properties(Dependent)
        mean
    end
    methods
        function value = get.mean(obj)
            value = mean(obj.values);
        end
    end
end

x = foobar;
x.mean
ans =
       4.3333


-- 
Loren
http://blogs.mathworks.com/loren/
0
loren5358 (941)
7/25/2008 2:10:22 PM
Reply: