gpt4 book ai didi

matlab - 连接并从元胞数组中提取数据

转载 作者:行者123 更新时间:2023-12-05 01:28:29 26 4
gpt4 key购买 nike

我有一个名为 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},...)

但这意味着要输入 15 次 data{i,1}。有什么更简单的方法?

最佳答案

vertcat(data{1:15,1})

vertcat(data{:,1})

它创建一个逗号分隔的列表并传递给 vertcat。

关于matlab - 连接并从元胞数组中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29148842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com