将 MATLAB char 数组转换为字符串 [英] Convert MATLAB char array to string

查看:63
本文介绍了将 MATLAB char 数组转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 MATLAB char 数组开始,A:

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'

如何将其转换为字符串单元 B,这样:

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

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

A 是一个单元格,使用 cellstr 函数会报错

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

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

推荐答案

使用如下函数:http://www.mathworks.com/help/matlab/ref/cellstr.html

>> B =  cellstr(A)

B = 

    'APR'
    'MAY'

>> B{1}

ans =

APR

这篇关于将 MATLAB char 数组转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆