2

I have 3 cell arrays :

c1={'a','b','c'}
c2={'a2','b2','c2'}
c3={'a3','b3','c3'}

How can I combine those 3 cell arrays into 1 cell array C as follows:

C={'a','b','c','a2','b2','c2','a3','b3','c3'}

2 Answers 2

2

You can simply use square brackets;

c = [c1, c2, c3]

% c = {'a'    'b'    'c'    'a2'    'b2'    'c2'    'a3'    'b3'    'c3'}

This can be used when appending items to the end of a cell too,

d1 = {'a', 'b', 'c', 'd'};
d2 = [d1, {'e'}];
Sign up to request clarification or add additional context in comments.

Comments

1

With colon you can create comma separated lists and then concatenate them:

c = {c1{:}, c2{:} ,c3{:}}

3 Comments

both of the answer are nice but rahnema1 commented first so I check the for him . Thanks all !
@kgk Thanks for acceptance, although I think Wolfie's answer is more acceptable:)
ok, then I will change the accepted answer to him :). Hope it is ok for you

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.