如何从MATLAB中的多个结构数组中读取特定字段?

时间:2013-02-20 16:13:26

标签: arrays matlab structure

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

Flight1=   

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

同样,多个航班有多个测试点。有没有办法检索仅指定测试点的数据?例如,我想查看其中.Mach = 0.8或其中.testpoint = 2的所有测试点的数据?

我希望我已经说清楚了。

1 个答案:

答案 0 :(得分:2)

假设你有一个struct array 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