How to prevent cell array within cell array

3 views (last 30 days)
Dear Experts
I have two cell arrays. One cell array is a combination of another cell array.
name = { 'Tom', 'Tim'};
record = {'school', 'class', name};
Output becomes nested cell arrays. Desired Output:
record = {'school', 'class', 'Tom', 'Tim'}
Thank you for your help
  1 Comment
Stephen23
Stephen23 on 19 Jul 2016
Edited: Stephen23 on 19 Jul 2016
>> record = [{'school', 'class'}, name]
record =
'school' 'class' 'Tom' 'Tim'

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 19 Jul 2016
It's simply
name = { 'Tom', 'Tim'};
record = [{'school', 'class'}, name]
  1 Comment
Guillaume
Guillaume on 19 Jul 2016
Of all, the answers here, this is the most appropriate. What is being asked is simply the concatenation of two cell arrays.
So:
x = [cellarray1, cellarray2];

Sign in to comment.

More Answers (2)

Andrei Bobrov
Andrei Bobrov on 19 Jul 2016
record = {'school', 'class', name{:}}

Star Strider
Star Strider on 19 Jul 2016
This works:
name = { 'Tom', 'Tim'};
record = {'school', 'class', name};
record2 = {record{1:2}, record{3}{1:2}};
record2 =
'school' 'class' 'Tom' 'Tim'

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!