function yes = ispartition (x,xc) % ISPARTITION checks if a cell array is a partition of a vector's values % yes = ispartition (x,xc) % x is a vector % xc is a cell array % yes is binary, equals 1 if xc is a partition of unique(x) if (size(x,1)==1),x=x';end yes = 0; xcall = []; for i=1:length(xc) if (size(xc{i},1)==1),xc{i}=xc{i}';end if length(intersect(xcall,xc{i})) % if xc{i} has any overlap with xc{1:i-1} return; else xcall = vertcat(xcall,xc{i}); end end a = sort(unique(x)); b = sort(xcall); if (length(a) == length(b)) if (max(abs(a-b))==0) yes = 1; end end