MATLAB: List of IDs to matrix of indexes

cell arrayscounting up

I have a list containing numbers like lijst = [1,1,1,2,2,3,3,3,3];
Now I want to make a matrix/cell array which counts up like:
A = [1,2,3;
4,5;
6,7,8,9];
(Essentially the number in the array is equal to the row in the matrix, and the number in the matrix is equal to the index of the array)
Is there a nice way to do this?

Best Answer

v = 1:numel(list);
[u,~,c] = unique(list);
Wanted = arrayfun(@(x) v(list == x), u,'un',0);
% or
Wanted = accumarray(c,v,[],@(x){x.'});
celldisp(Wanted)