How to convert 2*1 cell array into 1*2char array

조회 수: 9 (최근 30일)
raghavendra kandukuri
raghavendra kandukuri 2018년 10월 22일
댓글: raghavendra kandukuri 2018년 10월 23일
egr = Tier' % egr returns 'T2' 'S2' as 1*2 CELL
sgr = char(egr); % sgr returns T2
S2 as 2*2 char
My desired output should look like 'T2' 'S2' or 'T2','S2' in char
  댓글 수: 1
Guillaume
Guillaume 2018년 10월 22일
Note that the only way a 2x1 cell array can be converted into a 1x2 char array is if each cell of the array contain a single character, or one cell contains 2 characters and the other none.

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 23일
egr = {'T2' 'S2'};
sgr = ['''', strjoin(egr, ''' '''), ''''];
disp(sgr)
This will display as
'T2' 'S2'
which is to say that sgr will be a character vector that contains those literal characters, which appears to be what you are asking for.
However, this appears to have nothing to do with your switch statement, since you have
switch (T3)
and T3 has nothing to do with egr or sgr.
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 10월 23일
Note that in your switch,
case {'T2' 'S2'}
would match if Sgr is either 'T2' or 'S2', not if it is the character vector "'T2' 'S2'" .
If you are trying to indicate by case {'T2' 'S2'} that the condition should match if the input contained either 'T2' or 'S2' then you should probably be using any(ismember()) or similar.
raghavendra kandukuri
raghavendra kandukuri 2018년 10월 23일
Yeah, just now noticed that issue, thank you @ Walter Roberson

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

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 10월 22일
편집: madhan ravi 2018년 10월 22일
Tier={'T2';'S2'}'
egr=Tier
c=char(egr)
  댓글 수: 7
Image Analyst
Image Analyst 2018년 10월 22일
Try again - I rescued it from the spam quarantine.
raghavendra kandukuri
raghavendra kandukuri 2018년 10월 22일
Thank You @ Image Analyst

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by