0

我在 Matlab 的数据集中有大量横截面时间序列数据,我想根据标题提取数据数组(列),这些数据将从 for 循环中的另一个数组动态给出。任何人都可以建议如何在 Matlab 中实现这一点,我尝试了以下代码

cdslist = universe.Bond;
cdscount = length(universe.Bond);

for i=1:cdscount
    cds = cdslist(i);
% here i want to use this variable cds to dynamically give names to a dataset called spread, for instance spread.cds where cds is changing in the loop. 

end

这可能吗 ?谢谢您的帮助

4

1 回答 1

2

假设cds是一个字符串,它可以用作动态字段名称:

cdslist = universe.Bond;
cdscount = length(universe.Bond);

spread = struct;

for i = 1:cdscount
    cds = cdslist{i};
    spread.(cds) = data;
end
于 2013-08-07T11:38:18.410 回答