MATLAB: Do I get different results using the UNIQUE function for an empty cell array in MATLAB 7.8 (R2009a) compared to MATLAB 7.7 (R2008b)

MATLAB

I have recently upgraded MATLAB from R2008b to R2009a and could notice that there is difference in computation results for the same MATLAB code in R2008b and R2009a.
The following code:
[u,i,j] = unique(cell(0,1)) % also try zeros(1,0), zeros(0,0)
gave the following output in R2008b:
u =
{}
i =
[]
j =
[]
but gives the following in R2009a:
u =
Empty cell array: 0-by-1
i =
Empty matrix: 0-by-1
j =
Empty matrix: 0-by-1

Best Answer

The difference in these two results comes from a change that was made in the UNIQUE function in R2009a. When an empty cell array is input into UNIQUE since R2009a, the result is a 0x1 matrix (unlike before, where it was a 0x0 matrix). This change was made to so that the behavior of the UNIQUE function is consistent across all numeric arrays and cells.