So for example I have
1 1
1 3
1 9
2 4
2 7
I wan
Use accumarray
with a custom function
>> r = accumarray( A(:,1), A(:,2), [], @(x) {x'} ); %//'
r =
[1x3 double]
[1x2 double]
>> r{1}
ans =
1 3 9
>> r{2}
ans =
4 7
Update:
Converting cell r
to a matrix B
(accomodating further requests in comments):
>> [U ix iu] = unique( A(:,1) ); % see EitantT's comment
>> r = accumarray( iu, A(:,2), [], @(x) {x'} );
>> n = cellfun( @numel, r ); % fund num elements in each row - need for max
>> mx = max(n);
>> pad = 555555; % padding value
>> r = cellfun( @(x) [x pad*ones(1,mx - numel(x))], r, 'uni', 0 );
>> B = vertcat( r{:} ); % construct B from padded rows of r