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.
精彩评论