function [y_in_x,x_in_y]=cosmo_overlap(xs,ys)
% compute overlap between vectors or cellstrings in two cells
%
% [y_in_x,x_in_y]=cosmo_overlap(xs,ys)
%
% Inputs:
% xs Nx1 cell with all elements either numeric arrays or
% cells with strings
% ys Mx1 cell with all elements either numeric arrays or
% cells with strings
%
% Output:
% y_in_x MxN cell with the (i,j)-th element indicating the ratio of
% elements in ys{j} that are present in xs{i}
% x_in_i MxN cell with the (i,j)-th element indicating the ratio of
% elements in ys{i} that are present in ys{i}
%
% Examples:
% % Compute overlap between two cells with cellstrings
% xs={{'a'},{'a','b'},{'a','b','c'},{}};
% ys={{'b'},{'c','b','a'}};
% [x_in_y,y_in_x]=cosmo_overlap(xs,ys);
% cosmo_disp(x_in_y);
% %|| [ 0 0.333
% %|| 1 0.667
% %|| 1 1
% %|| 0 0 ]
% %||
% cosmo_disp(y_in_x);
% %|| [ 0 1
% %|| 0.5 1
% %|| 0.333 1
% %|| NaN NaN ]
%
% % Compute overlap between two cells with numeric arrays
% xs={1,[1 2],1:3,[]};
% ys={2,[3,2,1]};
% [x_in_y,y_in_x]=cosmo_overlap(xs,ys);
% cosmo_disp(x_in_y);
% %|| [ 0 0.333
% %|| 1 0.667
% %|| 1 1
% %|| 0 0 ]
% %||
% cosmo_disp(y_in_x);
% %|| [ 0 1
% %|| 0.5 1
% %|| 0.333 1
% %|| NaN NaN ]
%
%
% # For CoSMoMVPA's copyright information and license terms, #
% # see the COPYING file distributed with CoSMoMVPA. #