# How can I append a new cell onto the end of a Cell Array?

251 views (last 30 days)
Alex Hughes on 28 Apr 2020
Edited: Gali on 8 Jan 2023
Lets say I have a cell array C, with 1 column of different sized sub arrays (Example below)
C = {1x3 Cell};
{1x5 Cell};
{1x6 Cell};
Now lets say I have a new Cell F, and I want to append it to the end of Cell Array C.
F = {1x8 Cell};
I want to add F to C such that C looks like as follows:
C = {1x3 Cell};
{1x5 Cell};
{1x6 Cell};
{1x8 Cell}; % <--- This is Cell F
I want to do this to add new cells to the end of a primary cell array, without the need for loops. Is there any way to do this simply? I found a workaround by using length(CellArray) for the index position, but was hoping there would be an append() function or something.
Gali on 8 Jan 2023
Edited: Gali on 8 Jan 2023
I have similar case with more cell array in Group_1 of about 200cell, Group_2 = 50cell and Group_3 = 100cell. Basically I want to group them in the same place and then I can find the average of certain parameter. This is what I was trying but picking only the Group_1 and Group_2 and find the averages.
G_1 = (G{1,1}); %% string and number 1x150cell --- e.g (200X15 dataset, 500X15dataset, .........)
G_2 = (G{1,2}); %% string and number 1x50cell --- e.g (255X15 dataset, 25X15dataset, .........)
G_3 = (G{1,3}); %% string and number 1x100cell --- e.g (100X15 dataset, 50X15dataset, .........)
G_1_2 = [G_1; G_2];
also use G_1_2 = {G_1; G_2}
I want to combine G_1 and G_2 before calculating the aveage. Why is it working when G_1 and G_2 are numeric.
Thank very much

James Tursa on 28 Apr 2020
Edited: James Tursa on 28 Apr 2020
If F really is a cell array in the format you list, then just
C(end+1) = F;
If not, then you may have to do this:
C(end+1) = {F};

### Categories

Find more on Characters and Strings in Help Center and File Exchange

R2020a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!