# MATLAB: Extract and split data from cell into multiple cells.

cellpartitioning

So what I want to achieve is this:
I have a 1×3 cell of the form (date , hour, name):
so myCell has 3 100×1 cells;
ex : myCell (100×1 cell, 100×1 cell,100×1 cell):
07.03.2019 20:30 a
07.03.2019 20:31 b
07.03.2019 20:32 c
07.03.2019 20:33 a
07.03.2019 20:33 b
07.03.2019 20:34 c
07.03.2019 20:34 b
07.03.2019 20:35 c
07.03.2019 20:35 a
07.03.2019 20:36 c
I want to separate all my data from myCell into 3 diffrent cells each containing a or b or c;
ex:
myNewCellA:
07.03.2019 20:30 a
07.03.2019 20:33 a
07.03.2019 20:35 a
… myNewCellB with b, and myNewCellC with c;
Thank you in advance.

#### Best Answer

One approach:
C = {'07.03.2019 20:30' 'a'     '07.03.2019 20:31' 'b'     '07.03.2019 20:32' 'c'     '07.03.2019 20:33' 'a'     '07.03.2019 20:33' 'b'     '07.03.2019 20:34' 'c'     '07.03.2019 20:34' 'b'     '07.03.2019 20:35' 'c'     '07.03.2019 20:35' 'a'     '07.03.2019 20:36' 'c'};[U2,~,ix] = unique(C(:,2),'stable');myNewCell = splitapply(@(x){x}, C, ix);myNewCellA = myNewCell{1}                                     % Assign The Others Similarly, If You Want To
producing:
myNewCellA =  3×2 cell array    {'07.03.2019 20:30'}    {'a'}    {'07.03.2019 20:33'}    {'a'}    {'07.03.2019 20:35'}    {'a'}
You can always assign them as ‘myNewCellA’ and similarly for the rest, however that is ineffecient and makes it difficult to iterate through them. I would just refer to them as ‘myNewCell{1}’, ‘myNewCell{2}’, ...