Classdef: Difference between revisions

From Octave
Jump to navigation Jump to search
(local functiosn in classdef files)
(link to MATLAB doc)
Line 8: Line 8:
** <source lang="octave" enclose="none">classdef nonsense < uint32</source>
** <source lang="octave" enclose="none">classdef nonsense < uint32</source>


* array of objects. Example:
* [http://www.mathworks.com/help/matlab/matlab_oop/redefining-concatenation-for-your-class.html concatenating objects] into [http://www.mathworks.com/help/matlab/matlab_oop/initialize-object-arrays.html array of objects]. Example:
<source lang="octave">
<source lang="octave">
classdef MyClass < handle
classdef MyClass < handle

Revision as of 09:43, 19 June 2015

This page is a stub. We should begin documenting what classdef is implemented and what is not.

not supported

  • enumeration
  • build-in class as superclass
    • classdef nonsense < uint32
classdef MyClass < handle
end

c = MyClass();
cc = [c, c];   % won't work

For now you can use a cell-array of objects instead:

cc = {c, c};   % ok
classdef MyClass < handle
    properties (SetAccess = immutable)
        x
    end
    methods
        function obj = MyClass()
            x = rand();
        end
    end
end

Use "private" properties as workaround.

  • Function handles to package methods and static class methods.

For example if we have +mypackage/myfunc.m, creating a function handle as fh = @mypackage.myfunc won't work. As a workaround, we can create an indirection using an anonymous function fh = @(varargin) mypackage.myfunc(varargin{:}). Similarly for static class methods where fh = @MyClass.myfunc isn't yet supported.

  • Defining local functions in the same classdef-file is not working. For example, the following code gives a syntax/parse error:
classdef MyClass
    methods
        function obj = MyClass()
            myfunc()
        end
    end
end

function myfunc()
    disp('myfunc')
end

supported

  • methods
    • static
    • private

Classdef examples in the wild