如何将1x1单元转换为字符串?

6,154次观看(最近30天)
如何将1x1单元格转换为{ ' 线 ' } to a character vector like ' 线 ' , or a string like 请“线”。谢谢

接受的答案

Azzi Abdelmalek
Azzi Abdelmalek on 1 Feb 2015
编辑:Mathworks支金宝app持团队 2020年9月3日
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}
从R2016B开始,您可以将文本存储在字符串数组中。要将单元格数组转换为字符串数组,请使用“字符串”函数。
a = {'line'}
B = string(A)
有关更多信息,请参阅有关数学文档 Cell Arrays of Character Vectors Text in String and Charater Arrays .
5 Comments
Junho Kweon
Junho Kweon on 25 Apr 2019
那是小菜一碟。非常感谢!

Sign in to comment.

更多的Answers (2)

图像分析师
图像分析师 on 1 Feb 2015
Azzi向您展示了如何 extract 来自单元格的字符串。另一种方法是 convert the cell with char():
ca={'line'}% This is our cell array.
str = char(CA)% Convert it to a character array (string).
网络,都给出相同的结果,只是到达那里的不同方式。如果您的单元格数量仅是一个单元单元,那么您甚至不应首先使用单元格 - 使用字符串。

Morteza Darvish Morshedi
Morteza Darvish Morshedi 2019年6月14日
Even if you have more than 1 string in our cell array, an easy way can be:
S = {'你好',' ','世界'}
ss = [S{:}]
5 Comments
Morteza Darvish Morshedi
Morteza Darvish Morshedi on 20 Feb 2021
正确的。谢谢。

Sign in to comment.

Community Treasure Hunt

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

开始狩猎!