%% Group Values in Cell Array
% Create a vector of data and a matrix ind that defines groups of the data.

data = 1:10
ind = [1 1; 1 1; 1 1; 1 1; 2 1; 2 1; 2 1; 2 1; 2 1; 2 2]

%  Group the elements of data into a cell array.

B = accumarray(ind,data,[],@(x) {x})

% Verify that the vector elements are in the same order as they appear in data.

B{2,1}

% Copyright 2020 The MathWorks, Inc.