Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert MATLAB char array to string

Starting with the MATLAB char array, A:

A(1,1) = 'A'
A(1,2) = 'P'
A(1,3) = 'R'
A(2,1) = 'M'
A(2,2) = 'A'
A(2,3) = 'Y'

How can this be converted to a cell of strings, B, such that:

B{1} = 'APR'
B{2} = 'MAY'

Edit: A is a cell and using the function cellstr gives the error

Error using cellstr (line 23)
S must be 2-D. 
like image 353
rwolst Avatar asked May 01 '13 14:05

rwolst


1 Answers

Use the following function: http://www.mathworks.com/help/matlab/ref/cellstr.html

>> B =  cellstr(A)

B = 

    'APR'
    'MAY'

>> B{1}

ans =

APR
like image 59
Franck Dernoncourt Avatar answered Oct 01 '22 09:10

Franck Dernoncourt