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.

0

1 Answer 1

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

or

c{end+1}= [1, 2, 3, 4]
Sign up to request clarification or add additional context in comments.

3 Comments

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.
[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].
To complete the lesson: c(end+1)= {[1, 2, 3, 4]};. No better, but hopefully helps demonstrate MATLAB syntax a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.