0

Suppose I have a 3x1 cell array:

c = {[1, 2, 3]; [1, 2, 3, 4, 5]; [1, 2]}

I now want to add another array, to make it a 4x1 array. How do I do this? I have tried the following:

c = {c; [1, 2, 3, 4]}

But it then tells me that:

c = {3x1 cell}    [1x3 double]

Whereas I want:

c = {4x1 cell}

What should I do? Thanks.

Karnivaurus
  • 22,823
  • 57
  • 147
  • 247

1 Answers1

5
c=[c; [1, 2, 3, 4]]

or

c{end+1}= [1, 2, 3, 4]
Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thanks. In the first of your examples, why is the syntax to use a square bracket rather than a curly bracket for the outer bracket? I thought the square bracket would be just for adding an element to a regular array. – Karnivaurus Mar 17 '14 at 18:19
  • 1
    `[x,y]` is the syntax to concatenate. [1,2,3,4] concatenates four doubles to a vector. [{1},{1},{1},{1}] concatenates four cells to one cell. If mixed, it's implicit a cell: [{1},{1},1,1]. – Daniel Mar 17 '14 at 18:32
  • 2
    To complete the lesson: `c(end+1)= {[1, 2, 3, 4]};`. No better, but hopefully helps demonstrate MATLAB syntax a bit. – chappjc Mar 17 '14 at 18:50