将MATLAB char数组转换为字符串

时间:2013-05-01 14:47:22

标签: string matlab char

从MATLAB char数组开始,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'

如何将其转换为字符串B的单元格,以便:

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

编辑: A是一个单元格,使用函数cellstr给出错误

Error using cellstr (line 23)
S must be 2-D. 

2 个答案:

答案 0 :(得分:9)

使用以下功能:http://www.mathworks.com/help/matlab/ref/cellstr.html

>> B =  cellstr(A)

B = 

    'APR'
    'MAY'

>> B{1}

ans =

APR

答案 1 :(得分:2)

对于3D字符数组T

B = cellstr(T(1,:,:))

给出错误

Error using cellstr (line 23)
S must be 2-D.

首先将其分配给2D矩阵,然后使用上面提到的Franck建议的'cellstr'。

A(:,:) = T(1,:,:)
B = cellstr(A)
相关问题