Wrong value for nargout in subsref of type {}, .
Afficher commentaires plus anciens
I am overloading subsref in a class which implements a list.
function [varargout] = subsref(this, index)
switch index(1).type
case {'{}'}
vResult = this.GetItem(index(1).subs{:});
nResult = length(index);
if 1 == nResult
[varargout{1}] = vResult;
else
[varargout{1:nargout}] = builtin('subsref', vResult, index(2:nResult));
end
otherwise
[varargout{1:nargout}] = builtin('subsref',this,index);
end
When I do the following:
list = ArrayList(); % new instance of my list class
sig = Simulink.Signal(); % create another object
list.Add(sig); % add the object to my list
list{1}.disp(); % call a method without a return value
I get the error:
??? Error using ==> disp
Too many output arguments.
This is because nargout returns 1 in my subsref method but builtin('subsref', ...) doesn't return anything.
[varargout{1:nargout}] = builtin('subsref', vResult, index(2:nResult));
I can change the value of nargout implementing the numel method. However, the number of return values depends on the method I call (disp in this case) and not the indeces supplied to {}. But in numel I only get the indices of {}.
Is there a solution for this problem?
Réponses (0)
Catégories
En savoir plus sur Customize Object Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!