PDA

查看完整版本 : 您可以将字符串视为MATLAB中列表中的一个对象吗?


poster
2019-12-10, 20:41
我想使用以下示例在MATLAB中创建字符串列表:

x = ['fun', 'today', 'sunny'] 我希望能够调用x(1)并使它返回'fun' ,但是我一直在获取'f' 。

另外,有没有一种方法可以将字符串添加到列表中,而又不返回列表中应该包含字符串的数字?我尝试使用str2double和其他一些东西。看来这两个事情都应该可以在MATLAB中完成。



回答:

存储具有不同长度的字符串列表的最简单方法是使用单元格数组 (http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04bw6-98.html) 。例如:

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

更多&回答... (https://stackoverflow.com/questions/3064680)