MATLAB: How to convert 2 column matrix to a cell array

cell arrayMATLABmatrix arraymatrix manipulationvectorization

Is there a convenient way to convert a 2 column matrix into a cell array (without using nested for loops if possible)?
The matrix looks like:
1.PNG
Can I make a matrix from the above matrix such that the rows and columns of the new matrix(or a cell array you can say) will be like you see below:
3.JPGthe empty cells can be NAN and the filled cells are the values of the 3rd column of the old matrix.

Best Answer

result = accumarray(matrix(:,[2 1]), matrix(:,3), [], @(v) {v}, {nan})
However I wonder if you would be better off using
result = sparse(matrix(:,2), matrix(:,1), matrix(:,3))
which would be a sparse numeric array instead of a cell array that takes up about 108 bytes per entry.