MATLAB: Counting the number of values in table if the condition satisfies?

MATLAB

Hi,
I have 2 tables as
a =
y=
If the string in "y" matches with string in ''a'' i want to count all the strings after matching the strings.
I am looking for looping only not like count command.
Thanks in advance

Best Answer

xx = categorical({'computer'; 'car'; 'mobile'; 'bus'; 'tree'; 'jeep'});
u='car';
[ia,ib]=ismember(u,xx);
if ia
count=numel(xx)-2+1; % inclusive count
else
count=nan; % not found indicator
end
tables unnecessarily complicate life when they really have no useful reason for using them in a given case.
Using categorical for such variables simplilfies comparisons greatly; that's what they're for.
Above for a one-at-a-time lookup, loop over an array of u if needed...