2010-06-17 58 views
3

我想用以下的例子来使MATLAB字符串列表:你可以将字符串作为MATLAB中列表中的一个对象吗?

x = ['fun', 'today', 'sunny'] 

我希望能够调用x(1),并使其返回'fun',而是我不断收到'f'

另外,有没有一种方法可以添加一个字符串到列表中,而不必让列表返回一个字符串应该在的数字?我曾尝试使用str2double和其他一些东西。似乎这两个东西都应该可以在MATLAB中完成。

回答

4

存储具有不同长度的字符串列表的最简单方法是使用cell arrays。例如:

>> x = {'fun', 'today', 'sunny'}; %# Create a cell array of strings 
>> x{1}       %# Get the string from the first cell 

ans = 

fun 
1

这是种缺憾的解决方法,但 X = strsplit( 'fun.today.sunny', '') 产生与个人,可调用的字符串列表。

相关问题