MATLAB Answers

How to convert a 1x1 cell to a string?

10,828 ビュー (過去 30 日間)
bh dhouha
bh dhouha 2015 年 2 月 1 日
回答済み: Morteza Darvish Morshedi 2019 年 6 月 14 日
How to convert a 1x1 cell like {'line'} to a character vector like 'line', or a string like "line" please. thx

  0 件のコメント

サインイン to comment.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 2 月 1 日
編集済み: MathWorks Support Team 2018 年 11 月 27 日
To convert a cell array of character vectors to a character array, use the “char” function.
A = {'line'}
B = char(A)
To extract the contents from a cell, index using curly braces.
A = {'line'}
B = A{1}
Starting in R2016b, you can store text in string arrays. To convert a cell array to a string array, use the “string” function.
A = {'line'}
B = string(A)

  5 件のコメント

表示 2 件の古いコメント
Raman Shrestha
Raman Shrestha 2018 年 12 月 6 日
it has done magic to me thanks a lot
Yusuf Selim KARATAS
Yusuf Selim KARATAS 2019 年 2 月 15 日
Thanks Azzi Abdelmalek. Works perfect.
JUNHO KWEON
JUNHO KWEON 2019 年 4 月 25 日
That's a piece of cake. Thanks a lot!

サインイン to comment.

その他の回答 (2 件)

Image Analyst
Image Analyst 2015 年 2 月 1 日
Azzi showed you how to extract the string from a cell. Another way is to convert the cell with char():
ca={'line'} % This is our cell array.
str = char(ca) % Convert it to a character array (string).
Net, both give the same result, just different ways of getting there. If your cell array is only a single solitary cell, then you should not even use a cell in the first place - use a string.

  1 件のコメント

Image Analyst
Image Analyst 2015 年 2 月 1 日
Please read the FAQ for more insight: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F

サインイン to comment.


Morteza Darvish Morshedi
Morteza Darvish Morshedi 2019 年 6 月 14 日
Even if you have more than 1 string in our cell array, an easy way can be:
S = {'Hello',' ','world'}
ss = [S{:}]

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by