How to correctly method / operator overload size () in Matlab

I have a class with val property

classdef SomeClass < handle

properties
   val;
end
methods
    function sz = size(this,varargin)
        sz = builtin('size',this.val,varargin{:});
    end;
end
end

presumably, this should be the right way to overload this method to get the correct sizes of an object of the SomeClass class if it is defined as a matrix, i.e. val is the matrix. Type Assignment

a = size(b) % b is SomeClass object

works however

[a,b] = size(b)

no. This results in the "Too many output arguments" error. While the built-in method size for doubles (which is actually val) works with this syntax.

Can anyone give me a hint. What is the problem in this case?

+4
source share
1 answer

patrik, varargout...
nargout :

function varargout = size(this,varargin)
    [varargout{1:nargout}] = builtin('size',this.val,varargin{:});
end

- val, , size.

, :

Obj = SomeClass();
Obj.val = Obj;
size(Obj);

...

+2

All Articles