Help with methods()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with methods()

Rik-4
Trying to determine which methods are returned in Matlab from the methods()
function.  Could someone take the following code and put it in to a file
called "testclass.m".

-- START testclass.m --
classdef testclass

    properties
        testnumber = 0;
    end
   
    methods
        function p = testclass()
            p.testnumber = 1337;
        end
       
        function result = getNumber(obj)
            result = obj.testnumber;
        end
    end

  methods (Access = private)
        function result = privatemtd (obj)
            result = obj.testnumber;
        end
  end

  methods (Access = protected)
        function result = protectedmtd (obj)
            result = obj.testnumber;
        end
  end

  methods (Hidden = true)
        function result = hiddenmtd (obj)
            result = obj.testnumber;
        end
  end

end
-- END testclass.m --

Next, run the following and post the results.

-- START code --
x = testclass
methods (x)
methods (x, '-full')
-- END code --

One question is whether all public methods, including the constructor, are
returned.  The second question is whether protected or private methods are
returned.  Third question is whether hidden methods are returned.

--Rik

Reply | Threaded
Open this post in threaded view
|

Re: Help with methods()

nrjank


On Fri, Feb 22, 2019 at 11:34 AM Rik <[hidden email]> wrote:
Trying to determine which methods are returned in Matlab from the methods()
function.  Could someone take the following code and put it in to a file
called "testclass.m".


>> x = testclass
x =
  testclass with properties:
    testnumber: 1337

>> methods (x)
Methods for class testclass:
getNumber  testclass 

>> methods (x, '-full')
Methods for class testclass:
result getNumber(obj)
p testclass