24

As the title already mentions, how is it possible to add a new cell array 1x1 at the end of an existing cell array, let's call him Q, which is a cell array 1x3256?

Dan
  • 45,079
  • 17
  • 88
  • 157
nik-OS
  • 327
  • 1
  • 4
  • 14

2 Answers2

37

If you mean adding a single cell to the end (i.e. so your 1-by-3256 cell array becomes a 1-by-3257 cell array) then:

Q{end+1} = []

and you can replace [] with your value directly

Alternatively:

Q(end+1) = {[]}
Dan
  • 45,079
  • 17
  • 88
  • 157
13

Adding to Dan's answer, in case you have a cell that is not a single dimension cell, you might want to add a full row, for example. In that case, access the cell as an array using ().

>> c = { 1, 'a'; 2, 'b'}

c = 

    [1]    'a'
    [2]    'b'

>> c(end+1,:) = {3,'c'}

c = 

    [1]    'a'
    [2]    'b'
    [3]    'c'
aguadopd
  • 553
  • 8
  • 17