Is it possible to consider a string as one object in a list in MATLAB?

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

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

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

Also, is there a way to add a string to the list without getting a list returning the number where the string should be? I tried to use str2doubleseveral other things. It seems that both of these things should be possible in MATLAB.

+3
source share
2 answers

The easiest way to keep a list of strings of different lengths is to use cell arrays . For instance:

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

ans =

fun
+4

kludgy ,   x = strsplit ('fun.today.sunny', ',') , .

+1

Source: https://habr.com/ru/post/1750567/


All Articles