简体   繁体   English

MATLAB:创建一个字符串列表/单元格数组

[英]MATLAB: create a list/cell array of strings

data = {};
data(1) = 'hello';

gives this error Conversion to cell from char is not possible. 给出此错误Conversion to cell from char is not possible.

my strings are created inside a loop and they are of various lengths. 我的字符串是在一个循环中创建的,它们的长度各不相同。 How do I store them in a cell array or list ? 如何将它们存储在cell arraylist

I believe that the syntax you want is the following: 我相信你想要的语法如下:

data = {};
data{1} = 'hello';

Use curly braces to refer to the contents of a cell: 使用花括号来引用单元格的内容

data{1} = 'hello'; %// assign a string as contents of the cell

The notation data(1) refers to the cell itself, not to its contents. 符号data(1)指的是单元本身,而不是其内容。 So you could also use (but it's unnecessarily cumbersome here): 所以你也可以使用(但这里不必要的麻烦):

data(1) = {'hello'}; %// assign a cell to a cell

More information about indexing into cell arrays can be found here . 有关索引到单元阵列的更多信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM