ERROR- Too many outputs requested. Most likely cause is missing [] around left hand side that has a comma separated list expansion.
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
annu dahiya
on 4 Sep 2019
Bruno Luong
on 4 Sep 2019
Edited: Bruno Luong
on 4 Sep 2019
what is the size (not length) of list?
annu dahiya
on 4 Sep 2019
Bruno Luong
on 4 Sep 2019
Edited: Bruno Luong
on 4 Sep 2019
That's the source of the problem
list{ i }
is "emptyness", you can't assign nothing to something (class on the LHS).
You might change your test to
if isempty(n) || n( i ) == 0, ...
annu dahiya
on 4 Sep 2019
Bruno Luong
on 4 Sep 2019
See my post edited
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
0 votes
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.
Categories
Find more on Data Type Conversion 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!