如何在Matlab中将逗号分隔的字符串转换为字符串的单元格数组 [英] How to convert comma-separated string to cell array of strings in matlab
本文介绍了如何在Matlab中将逗号分隔的字符串转换为字符串的单元格数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下字符串
'A,B,C,D'
我要从中制作一个像这样的单元格数组
from which I want to make a cell array such as
{'A','B','C','D'}
{ 'A', 'B', 'C', 'D' }
我如何在Matlab中做到这一点?
How would I be able to do this in Matlab?
推荐答案
这是一个解决方案,它将在逗号,分号或空格处截断字符串,并且适用于任何长度的字符串
Here's a solution that will cut up the string at commas, semicolons, or white spaces, and that will work for strings of any length
string = 'A, BB, C'
tmp = regexp(string,'([^ ,:]*)','tokens');
out = cat(2,tmp{:})
out =
'A' 'BB' 'C'
这篇关于如何在Matlab中将逗号分隔的字符串转换为字符串的单元格数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文