MATLAB: Using bsxfun for non-numeric data

bsxfuncell

Is there an equivalent to bsxfun for non-numeric data?
For example, I want to compare all pairs of strings stored in two cell-arrays:
a = {'aa', 'bb', 'cc'};
b = {'dd', 'aa'};
bsxfun( @strcmp, a, b' ); % not working for cells
I want something like this:
bsxfun(@eq, 1:3, (1:4)')
ans =
1 0 0
0 1 0
0 0 1
0 0 0

Best Answer

Here's a way you could still do the comparison in the "string domain",
>> ia=(1:length(a)).'; ib=1:length(b);
>> a=a(:);
>> bsxfun(@(i,j) strcmp( a(i),b(j) ) ,ia, ib)
ans =
0 1
0 0
0 0