【问题标题】:Dataset in MatlabMatlab 中的数据集
【发布时间】:2013-08-07 20:03:31
【问题描述】:

我在 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

这可能吗? 感谢您的帮助

【问题讨论】:

    标签: matlab dataset


    【解决方案1】:

    假设cds是字符串,可以作为动态字段名:

    cdslist = universe.Bond;
    cdscount = length(universe.Bond);
    
    spread = struct;
    
    for i = 1:cdscount
        cds = cdslist{i};
        spread.(cds) = data;
    end
    

    【讨论】:

    • 你甚至可以不用cds,只需使用:spread.(cdslist(i))
    • 你能澄清一下什么是数据吗?
    • 事物已作为具有横截面数据的数据集存在,我想从中提取数据以获得安全名称,例如 cdslist 给出的“X”
    • data 只是分配给结构的一个示例。 spread的数据结构是什么? “X”是元素之一吗?如果您提供数据集和预期结果的示例,那么我可能会提供帮助。
    • 谢谢,我还有一个疑问。 cds 是 1x1 单元格格式。如何将其转换为字符串?
    猜你喜欢
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 2014-04-14
    相关资源
    最近更新 更多