I am overloading subsref in a class (reason is out topic here). Say for simplicity that my subsref should have the same behaviour as the builtin subsref in everycase. So I simply wrap a call to the builtin. But when using instance.some_cell{:}, where some_cell is a cell attribute, only the first element of the instance.some_cell is returned by my subsref.
In the following exemple, you can see a if bloc in subsref. Its only purpose is to pick the proper nargout size. The debugger shows me that varargout is of correct size (ie 3) right before my subsref returns. However, once my subsref is done, I only receive the first cell element oustide !!!
instance= exemple_subsrf_oncell({1,2,3}); instance.some_cell instance.some_cell{:} %WEIRD returns only 1
I know numel isn't involved here, because some_cell is of a builtin type. I wonder how I should define subsref so that it returns me the proper number of outputs when using expression like instance.some_cell{:} I wish to let matlab find the proper nargout alone (the uggly if block in subsref is just a stupid attempt to solve the problem).
exemple class code
classdef exemple_subsrf_oncell < handle properties some_cell= {}; end methods function self= exemple_numel(cn) self.some_cell= cn; end function varargout= subsref(self,idx) if isequalwithequalnans(idx(end),substruct('{}',{':'})) varargout= cell(1,length(self.some_cell)); else varargout= cell(1,1); end [varargout{:}]= builtin('subsref',self,idx); end end end
Thank you very much for your attention
Best Answer