【问题标题】:How to read specific fields from multiple structure arrays in MATLAB?如何从 MATLAB 中的多个结构体数组中读取特定字段?
【发布时间】:2013-02-20 16:13:26
【问题描述】:

我有一个非常大的数据集,在 MATLAB 中排列成多个结构体数组。结构看起来像这样:

Flight1=   

.testpoint = 1
.Mach = 0.8
.Speed = 300
.Cieling = 35000
.Data = [A] % A is an MxN matrix

同样,多次飞行也有多个测试点。有没有办法只检索指定测试点的数据?例如,我想查看 .Mach = 0.8 或 .testpoint = 2 的所有测试点的数据?

我希望我已经说得够清楚了。

【问题讨论】:

    标签: arrays matlab structure


    【解决方案1】:

    假设您有一个结构数组Flight,其中Flight( k ) 是一个包含您描述的字段的结构,那么:

    sel = [ Flight(:).Mach ] == 0.8; % select all flights with Mach == 0.8
    poitEightMach = Flight( sel );   % selecting them into a separate struct array
    
    sel = [Flight(:).testpoint] == 2;
    testPoint2 = Flight( sel );   % select all flights with testpoint == 2
    

    【讨论】:

    • 结构采用这种格式: Flight = Flight1: [1x1 struct] Flight2: [1x1 struct] Flight3: [1x1 struct] Flight4: [1x1 struct] 当我应用你提到的代码时,MATLAB给我这个错误:引用不存在的字段“马赫”。文件读取错误(第 57 行) sel = [ Flight(:).Mach ] == 0.8
    • @user2091834 请看我对that question的回复
    • 在我的一生中,我无法弄清楚为什么我在访问多个结构值时遇到问题,无论我尝试什么,只会返回第一个值......您对方括号的使用已修复这一切。谢谢。
    猜你喜欢
    • 2020-10-28
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    相关资源
    最近更新 更多