Hello Sir!
How to convert a cell array to char array? I want to read 2 strings from a .txt file and want them in char type. if I do as follow those are cell type. The file contains 2 strings in 1st line, separated by a single space.
[a,b] = textread('inp.txt','%s%s',1)

 采纳的回答

Walter Roberson
Walter Roberson 2011-1-26

9 个投票

char(a) and char(b)

4 个评论

it works for a string other than numeric values. what to do for a string containing numeric or alpha-numeric value for converting it in char type?
>> a = {'9a','abc'}
a =
'9a' 'abc'
>> char(a)
ans =
9a
abc
Tank you sir!
alternatively,
>> a = {'9a','abc'}
a =
1×2 cell array
{'9a'} {'abc'}
>> a{1}
ans =
'9a'

请先登录,再进行评论。

更多回答(1 个)

piyari sadia
piyari sadia 2011-8-17

0 个投票

letters_lut ='AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'; HOW (letters_lut) is used to convert the cell array to a character?

1 个评论

Please expand on your question. Conversion from cell array to character string is a matter of de-referencing each of the cell array entries to get the already-contained character string, and building up rows of a char array, with the rows padded (with blanks) to the length of the longest string. There is no look-up table involved in the process.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by