连接并从元胞数组中提取数据
Concatenate and pull out data from cell array
我有一个名为 d_O3 的元胞数组,大小为 3x15。
第一行如下所示:
10x29 cell
31x29 cell
40x29 cell
...
我想将每个单元格中的第一列变成一个列数组,然后将它们垂直连接在一起。
这是我目前所做的:
years = 1999:2013; % The 15 columns
m = 1; % Row 1. I'd like to be able to run a loop for the other rows to do the same thing, but I haven't figured out how.
for y = 1:numel(years)
data{y,1} = d_O3{m.y}(:,1);
end
这会创建一个 15x1 的单元格,内部看起来像这样:
31x1 单元格
40x1 单元格
42x1 单元格
...
在每个单元格内(即在 31x1 内),有一列字符串数组。但我希望它全部连接在一起,所以它看起来像:
06-029-0001-88101
06-073-0010-88101
...
换句话说,我想垂直连接上面的所有单元格。
我可以通过以下方式做到这一点:
vertcat(data{1,1},data{2,1},...)
但这意味着要输入 data{i,1}
15 次。有什么更简单的方法?
vertcat(data{1:15,1})
或
vertcat(data{:,1})
它创建一个逗号分隔的列表并传递给 vertcat。
我有一个名为 d_O3 的元胞数组,大小为 3x15。 第一行如下所示:
10x29 cell
31x29 cell
40x29 cell
...
我想将每个单元格中的第一列变成一个列数组,然后将它们垂直连接在一起。
这是我目前所做的:
years = 1999:2013; % The 15 columns
m = 1; % Row 1. I'd like to be able to run a loop for the other rows to do the same thing, but I haven't figured out how.
for y = 1:numel(years)
data{y,1} = d_O3{m.y}(:,1);
end
这会创建一个 15x1 的单元格,内部看起来像这样: 31x1 单元格 40x1 单元格 42x1 单元格 ...
在每个单元格内(即在 31x1 内),有一列字符串数组。但我希望它全部连接在一起,所以它看起来像:
06-029-0001-88101
06-073-0010-88101
...
换句话说,我想垂直连接上面的所有单元格。
我可以通过以下方式做到这一点:
vertcat(data{1,1},data{2,1},...)
但这意味着要输入 data{i,1}
15 次。有什么更简单的方法?
vertcat(data{1:15,1})
或
vertcat(data{:,1})
它创建一个逗号分隔的列表并传递给 vertcat。