MATLAB: Store values from loop in an array

loop

I want to compare each individual element of A with each element of B and store the logical answer in a table. Thanks for the help!
A= categorical ({'A','B','C'});
B= categirial({'B','D'});
TableA = zeros(3,2);
for i = length(A)
for j=1:length(B)
if isequal (A(i),B(j))
Answer=1;
tableA (i,j) = [Answer];
else
Answer=0;
tableA (i,j)= [Answer];
end
end
end

Best Answer

Typos in your code:
for i=1:length(A)
And change tableA to TableA (MATLAB is case sensitive).
Or, you could get rid of the loops entirely:
TableA = (A'==B);
On older versions of MATLAB:
TableA = bsxfun(@eq,A',B);