MATLAB: Best way to union a cell array containing cells

arrays union cells

My question is how would I obtain a single cell array of cells with unique values by combining two cell arrays of cells?
Let's say there are 2 cell arrays
A = {[1,1] [1,2]};
B = {[1,1] [1,3]};
I want to union them to achieve
C = {[1,1] [1,2] [1,3]};
I have tried converting them to strings and union-ing those which almost gets me there but the problem is that, obviously, I lose the ability to use the stored cells as cells.

Best Answer

In the restricted case where the cells contain numeric rows and the rows are all the same size:
t = union(cell2mat(A(:)),cell2mat(B(:)),'rows');
C = mat2cell(t, ones(1, size(t,1)), size(t,2) );
If that is not the case, please indicate what might kinds of values might be encountered.