Videos
In addition to @Adriaan's answer, note that you can also do this with concatenation, if you are careful.
>> c = {1, 2}
c =
1x2 cell array
{[1]} {[2]}
>> [c, {[]}]
ans =
1x3 cell array
{[1]} {[2]} {0x0 double}
The trick here is to concatenate explicitly with another cell (your question suggests you tried [c, []] which does indeed do nothing at all, whereas [c, 1] automatically converts the raw 1 into {1} before operating).
(Also, while pre-allocation is definitely preferred where possible, in recent versions of MATLAB, the penalty for growing arrays dynamically is much less severe than it used to be).
You can just append it by using end+1:
c={[1],[2]}
c =
[1] [2]
c{end+1} = [] % end+1 "appends"
c =
[1] [2] []
MATLAB note: appending is usually used as a way to grow an array in size within a loop, which is not recommended in MATLAB. Instead, use pre-allocation to initially apply the final size whenever possible.
You can't use
c = row1;
c = [cell; row2]
because the numbers of columns in the two rows don't match. In a cell array, the number of columns has to be the same for all rows. For the same reason, you can't use this either (it would be equivalent):
c = row1;
c(end+1,:) = row2
If you need different numbers of "columns in each row" (or a "jagged array") you need two levels: use a (first-level) cell array for the rows, and in each row store a (second-level) cell array for the columns. For example:
c = {row1};
c = [c; {row2}]; %// or c(end+1) = {row2};
Now c is a cell array of cell arrays:
c =
{1x3 cell}
{1x4 cell}
and you can use "chained" indexing like this: c{2}{4} gives the string 'foo4', for example.
The best way would be like so:
row1 = {'foo1', 'foo2', 'foo3'};
row2 = {'foo1', 'foo2', 'foo3', 'foo4'};
row3 = {'foo1', 'foo2'};
cell = row1;
cell = {cell{:}, row2{:}};
cell = {cell{:}, row3{:}}
Divakar's answer does not produce a cell as output.
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) = {[]}
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'