How to convert a 1x1 cell to a string?

bh dhouha (view profile)

on 1 Feb 2015
Latest activity Answered by Morteza Darvish Morshedi

Morteza Darvish Morshedi (view profile)

on 14 Jun 2019 at 18:53

Azzi Abdelmalek (view profile)

How to convert a 1x1 cell like {'line'} to a character vector like 'line', or a string like "line" please. thx

Azzi Abdelmalek (view profile)

on 1 Feb 2015
Edited by MathWorks Support Team

MathWorks Support Team (view profile)

on 27 Nov 2018

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)

Raman Shrestha

Raman Shrestha (view profile)

on 6 Dec 2018
it has done magic to me thanks a lot
Yusuf Selim KARATAS

Yusuf Selim KARATAS (view profile)

on 15 Feb 2019
Thanks Azzi Abdelmalek. Works perfect.
JUNHO KWEON

JUNHO KWEON (view profile)

on 25 Apr 2019
That's a piece of cake. Thanks a lot!

Image Analyst (view profile)

on 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.

Image Analyst

on 1 Feb 2015