开发者

Can you treat a string as one object in a list in MATLAB?

I would like to make a list of strings in MATLAB using the example below:

开发者_运维技巧
x = ['fun', 'today', 'sunny']

I want to be able to call x(1) and have it return 'fun', but instead I keep getting 'f'.

Also, is there a way to add a string to a list without getting the list giving back a number where the string should be? I have tried using str2double and a few other things. It seems like both of these thing should be possible to do in MATLAB.


The easiest way to store a list of strings that have different lengths is to use cell arrays. For example:

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

ans =

fun


It's kind of a kludgy workaround, but x = strsplit('fun.today.sunny', ',') produces a list with individual, callable strings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜