gpt4 book ai didi

string - 在 MATLAB 中,您可以将字符串视为列表中的一个对象吗?

转载 作者:太空宇宙 更新时间:2023-11-03 20:22:49 25 4
gpt4 key购买 nike

我想使用下面的示例在 MATLAB 中创建一个字符串列表:

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

我希望能够调用 x(1) 并让它返回 'fun',但我却一直收到 'f'.

此外,有没有一种方法可以将字符串添加到列表中,而无需让列表返回字符串应在的位置的数字?我试过使用 str2double 和其他一些东西。似乎这两件事都应该可以在 MATLAB 中完成。

最佳答案

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

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

ans =

fun

关于string - 在 MATLAB 中,您可以将字符串视为列表中的一个对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3064680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com