Convert char to string

I just want to convert a char to str.
The char is in a cell. This is what happens:
>> example = ['hithere',socks]
example =
'hithere' [1x34 char]
>> taken = ['hithere',{socks}]
taken =
'hithere' {1x1 cell}
>> socks
socks =
'Shane'
What am I doing wrong and how can I convert the char into a string.
Cheers, Shane

답변 (2개)

Walter Roberson
Walter Roberson 2012년 12월 20일

1 개 추천

I'm not sure but I think perhaps what you want is
[{'hithere'} socks]
But possibly what you want is
['hithere ' socks{1}]
Image Analyst
Image Analyst 2012년 12월 20일

0 개 추천

I don't know how socks was 34 characters in the first example and only 5 characters ('Shane') in the next example. Are any of these what you want:
socks = {'Shane'}
example = ['hithere',socks]
example1 = char(example)
example2 = sprintf('%s %s', example{1}, example{2})

댓글 수: 1

Jan
Jan 2012년 12월 20일
I'm still confused about ['string', {'Cell string'}], because it looks like this joins elements of incompatible types. I never had tried it without explicitly converting the string by cellstr() at first.

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

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2012년 12월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by