MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   您可以将字符串视为MATLAB中列表中的一个对象吗? (https://www.labfans.com/bbs/showthread.php?t=23540)

poster 2019-12-10 20:41

您可以将字符串视为MATLAB中列表中的一个对象吗?
 
我想使用以下示例在MATLAB中创建字符串列表:

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

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



[B]回答:[/B]

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

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

[url=https://stackoverflow.com/questions/3064680]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 14:17

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.