ERROR- Too many outputs requested. Most likely cause is missing [] around left hand side that has a comma separated list expansion.
3 views (last 30 days)
Show older comments
function class = find( name, op, varargin )
list = misc.subclasses( 'bembase' );
% number of NEEDS agreements with options
n = zeros( size( list ) );
% add property pairs to option structure
for i = 1 : 2 : length( varargin )
op.( varargin{ i } ) = varargin{ i + 1 };
end
% loop through list
for i = 1 : length( list )
% classes with name matching NAME
if strcmp( eval( [ list{ i }, '.name' ] ), name )
% get needs of class
needs = eval( [ list{ i }, '.needs' ] );
% loop over NEEDS
for j = 1 : length( needs )
if ischar( needs{ j } )
needs{ j } = isfield( op, needs{ j } ) && ...
~isempty( op.( needs{ j } ) );
else
% get fieldname of structure
fname = subsref( fieldnames( needs{ j } ), substruct( '{}', {} ) );
% compare with OP entries
needs{ j } = isfield( op, fname ) && ...
isequal( op.( fname ), needs{ j }.( fname ) );
end
end
% number of agreements
if all( cell2mat( needs ) ), n( i ) = numel( needs ); end
end
end
% find maximum number of agreements
[ ~, i ] = max( n );
% return name of class or empty cell if not all options match
if n( i ) == 0, class = {}; else class = list{ i }; end
showing error
Too many outputs requested. Most likely cause is missing [] around left hand side
that has a comma separated list expansion.
Error in bembase.find (line 51)
if n( i ) == 0, class = {}; else class = list{ i }; end
8 Comments
Steven Lord
on 4 Sep 2019
function class = find( name, op, varargin )
I strongly recommend you rename your function. Code that calls find expecting to call the built-in function but instead calls your function are likely to be unhappy.
% classes with name matching NAME
if strcmp( eval( [ list{ i }, '.name' ] ), name )
Avoid using eval if possible. In this case, if list{i} is an object you can through dynamic field names. [Yes, I know objects aren't struct arrays. The syntax still works.]
I'm not completely sure what your function is trying to do, but I suspect there may be functionality in MATLAB already that you can use to do what you want. [I'm thinking perhaps the functions for working with class metadata or perhaps a digraph to analyze dependencies between objects.] Can you describe in words the purpose of your function to help us determine if I'm right?
Answers (1)
Walter Roberson
on 4 Sep 2019
Your n is coming out empty because list is empty. max() of empty returns empty into i . list{i} is empty emptiness, no outputs, so assigning it to something is too many outputs.
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!