我在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
这可能吗? 谢谢你的帮助
答案 0 :(得分:2)
假设cds
是一个字符串,它可以用作动态字段名称:
cdslist = universe.Bond;
cdscount = length(universe.Bond);
spread = struct;
for i = 1:cdscount
cds = cdslist{i};
spread.(cds) = data;
end