如何在Matlab中从单元格数组创建子单元格?

时间:2018-02-22 20:47:14

标签: matlab cell-array

假设我在Matlab中有以下单元格数据:

Foo

然后我想创建一个只有第一列数据的新单元格数组。我尝试了以下操作,但只改为>> data = {'first', 1; 'second', 2; 'third', 3} data = 'first' [1] 'second' [2] 'third' [3] 值。

first

但我想得到的是:

>> column_1 = data{:,1}

column_1 =

first

如何从>> column_1 = {'first';'second';'third'} column_1 = 'first' 'second' 'third' 单元格数组的第一列创建子单元?

1 个答案:

答案 0 :(得分:2)

您必须使用圆括号索引而不是花括号索引,如下所示:

data(:,1)

输出:

ans =
      3×1 cell array
      'first'
      'second'
      'third'

基本上,花括号的目的是检索单元格的基础内容并呈现不同的行为。要提取单元格子集,您需要使用圆括号。有关更多详细信息,请参阅Matlab官方文档的this page