This should just use the built-in structure SUBSREF to access the data. You may want to add special cases, for example if you're indexing your object such as the following:
x(1:2)
Then you need to make sure you convert the varargout elements to class objects, such as the following:
If you are experiencing problems with SUBSREF not returning the correct number of comma separated list outputs, see Related Solution "When indexing into my MATLAB object and returning a comma separated list, why don't I get the correct number of outputs?" listed below.
Hi Ian, It turns out that subsref does have a varargout signature (it's just not documented). Here's the function signature you want:
function varargout = subsref(obj,s)
varargout{1:nargout} = builtin('subsref',obj,s);
end
You would probably want to make sure that '.' and '{}' use the varargout functionality, as they can both return comma separated lists. I'm also guess that you'll want to overload numel for your brace indexing.
Best Answer