Why does MATLAB throw a “too many output arguments” error when I overload subsref (subscripted reference)?

后端 未结 4 1892
别跟我提以往
别跟我提以往 2021-02-09 14:09

As a toy example, I have a class that simply wraps a vector or matrix in an object and includes a timestamp of when it was created. I\'m trying to overload

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 14:31

    This solution seems to work in 2014b (but not entirely certain why)

    classdef TestClass < handle
        methods
    
            function n = numel(~,varargin)
                n = 1;
            end
    
            function varargout = subsref(input,S)
                varargout = builtin('subsref',input,S);
            end
    
            function out = twoOutputs(~)
                out = {}; out{1} = 2; out{2} = 3; 
            end
        end
    end
    

    Then via the command window

    >> testClass = TestClass();
    >> [a,b] = testClass.twoOutouts()
    a =
    
         2
    
    b =
    
         3
    

提交回复
热议问题