Undefined variable "numel" or class "numel"
2 views (last 30 days)
Show older comments
Talent Mukaro
on 16 Jun 2020
Commented: Talent Mukaro
on 16 Jun 2020
Hie, how can i solve the above error in this code as below;
repelem = {};
for ii = 1:numel{subset}
subsetLabels{ii} = repelem{{subset{ii}.Description},subset{ii}.Count,1};
end
subsetLabels = vertcat(subsetLabels{:});
%nume1 = {};
togglefig('Sample Images',1)
[hpos,hdim] = distributeObjects(numel(subset),0.05,0.95,0.01);
[vpos,vdim] = distributeObjects(3,0.95,0.05,0.025);
ax = gobjects(numel(subset),1);
[hind,vind] = meshgrid(1:numel(imgSet),1:subset(1).Count);
for ii = 1:numel(subsetNames)
ax(ii) = axes('Units','Normalized',...
'Position',...
[hpos(hind(ii)) vpos(vind(ii)) hdim vdim]);
imshow(subsetNames{ii});
title(subsetLabels{ii},'fontsize',12)
end
expandAxes(ax);
2 Comments
Gautam
on 16 Jun 2020
for ii = 1:numel{subset} ------------------>>> change the bracket i.e numel(subset)
Accepted Answer
More Answers (1)
Walter Roberson
on 16 Jun 2020
for ii = 1:numel{subset}
That requests that a variable named numel is indexed as a cell array, at offset subset
subsetLabels{ii} = repelem{{subset{ii}.Description},subset{ii}.Count,1};
That requests that a variable named repelem be indexed as a cell.
In MATLAB, the {} operators are used for creating cell arrays, and for indexing "inside" cell arrays, string objects, table objects, and a few other kinds of object.
ax = gobjects(numel(subset),1);
That requests that the numel function be executed on the content of the variable subset . That looks quite reasonable to do.
A function name with () after it indicates invoking a function.
An array with () after it indicates indexing into the array. This is the same () appearance as for functions being invoked, so they can be confused at first glance.
This line of code asks to invoke numel on subset, and then it takes the result of that and takes the constant 1, and uses them as parameters to invoke the gobjects function.
numel{subset}
Not likely to work. You probably do not have a variable named numel to index into. More likely is that you want to invoke numel function on subset, just like you did on constructing ax
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!