【问题标题】:Constructing structure for wind data构建风数据结构
【发布时间】:2015-09-16 07:22:49
【问题描述】:

我一直在尝试使用struct函数在matlab中为风数据构造一个结构:

struct(fieldname1,value1,fieldname2,value2,......).

我有不同高度的风速和风向,例如40,50,80,90 米。问题是我不明白如何为我的大数据表示“价值”。

 wind_data=struct(ws40,[],ws50,[],ws80,[],ws90,[],wd40,[],wd50,[],wd80,[],wd90,[])

ws=风速。 wd=风向,每一个都是向量。

【问题讨论】:

  • 最佳格式可能取决于您需要对数据做什么。为什么是结构?由于速度不是向量,我假设wswd 在给定高度包含多个重复/位置?在这种情况下,每个高度的字段如何,包含该高度的所有数据速度和方向数据,例如struct("h40",{ws,wd})。请注意,字段名是一个字符串。因此人们可以提供帮助,请添加有关您计划做什么的更多信息..

标签: matlab for-loop structure


【解决方案1】:

您可以手动分配结构:

wind_data.ws40 = [1, 2, 3];
wind_data.wd40 = [4, 5, 6];
wind_data.ws50 = [11, 22, 33];
wind_data.wd50 = [44, 55, 66];

或动态:

heights = [40, 50, 80, 90];
ws      = round(10*rand(4,3));
wd      = round(10*rand(4,3));

for hh = 1:numel(heights)
    wind_data.( [ 'ws' num2str(heights(hh)) ] ) = ws(hh,:)
    wind_data.( [ 'wd' num2str(heights(hh)) ] ) = wd(hh,:)
end

或直接分配它们,你必须将字段名放在''中,因为Ed Smith已经说过:

heights = [40, 50, 80, 90];
ws      = round(10*rand(4,3));
wd      = round(10*rand(4,3));

wind_data = struct('ws40', ws(1,:), ...
                   'wd40', wd(1,:), ...
                   'ws50', ws(2,:), ...
                   'wd50', wd(2,:) );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 2016-05-21
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    相关资源
    最近更新 更多