How to prevent cell array within cell array

13 Ansichten (letzte 30 Tage)
Cheerful
Cheerful am 19 Jul. 2016
Kommentiert: Guillaume am 19 Jul. 2016
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 Kommentar
Stephen23
Stephen23 am 19 Jul. 2016
Bearbeitet: Stephen23 am 19 Jul. 2016
>> record = [{'school', 'class'}, name]
record =
'school' 'class' 'Tom' 'Tim'

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 19 Jul. 2016
It's simply
name = { 'Tom', 'Tim'};
record = [{'school', 'class'}, name]
  1 Kommentar
Guillaume
Guillaume am 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];

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

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

Star Strider
Star Strider am 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'

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by