%% Group Values in Cell Array
% Create a vector of data val and a matrix of subscripts subs.

val = 1:10;
subs = [1 1;1 1;1 1;1 1;2 1;2 1;2 1;2 1;2 1;2 2]

% The subscripts in subs define a 2-by-2 matrix for the output.
%
% Use accumarray to group the elements of val into a cell array.

A = accumarray(subs,val,[],@(x) {x})

% The result is a 2-by-2 cell array.
%
% Verify that the vector elements are in the same order as they appear in val.

A{2,1}

% Copyright 2019 The MathWorks, Inc.