# How to convert a 1x1 cell to a string?

3.643 visualizzazioni (ultimi 30 giorni)
bh dhouha il 1 Feb 2015
Commentato: Paula Camila il 19 Feb 2023
How to convert a 1x1 cell like {'line'} to a character vector like 'line', or a string like "line" please. thx
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Azzi Abdelmalek il 1 Feb 2015
Modificato: MathWorks Support Team il 3 Set 2020
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)
For more information, please refer to the MathWorks documentation on Cell Arrays of Character Vectors and Text in String and Charater Arrays.
##### 6 CommentiMostra 4 commenti meno recentiNascondi 4 commenti meno recenti
Junho Kweon il 25 Apr 2019
That's a piece of cake. Thanks a lot!
Paula Camila il 19 Feb 2023
gracias

Accedi per commentare.

### Più risposte (2)

Image Analyst il 1 Feb 2015
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 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Image Analyst il 1 Feb 2015

Accedi per commentare.

Morteza Darvish Morshedi il 14 Giu 2019
Even if you have more than 1 string in our cell array, an easy way can be:
S = {'Hello',' ','world'}
ss = [S{:}]
##### 5 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
Image Analyst il 15 Feb 2021
Just a point of clarification. ss is a character array while str is a string. A few versions ago, MATLAB made these different types of variables, though in common speech, people call either one "strings".
Morteza Darvish Morshedi il 20 Feb 2021
Right. Thanks.

Accedi per commentare.

### Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by