How to prevent cell array within cell array

조회 수: 13 (최근 30일)
Cheerful
Cheerful 2016년 7월 19일
댓글: Guillaume 2016년 7월 19일
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
Stephen23
Stephen23 2016년 7월 19일
편집: Stephen23 2016년 7월 19일
>> record = [{'school', 'class'}, name]
record =
'school' 'class' 'Tom' 'Tim'

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 19일
It's simply
name = { 'Tom', 'Tim'};
record = [{'school', 'class'}, name]
  댓글 수: 1
Guillaume
Guillaume 2016년 7월 19일
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];

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2016년 7월 19일
record = {'school', 'class', name{:}}

Star Strider
Star Strider 2016년 7월 19일
This works:
name = { 'Tom', 'Tim'};
record = {'school', 'class', name};
record2 = {record{1:2}, record{3}{1:2}};
record2 =
'school' 'class' 'Tom' 'Tim'

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by