How to read specific fields from multiple structure arrays in MATLAB?

Hello,
I have a very large dataset arranged into multiple structure arrays in MATLAB. The structures look something like this:
Flight1=
.testpoint = 1
.Mach = 0.8
.Speed = 300
.Cieling = 35000
.Data = [A] % A is an MxN matrix
Similarly there are multiple test points for multiple flights. Is there a way to retrieve the Data of only specified test points? For example I want to plot and compare the Data of ALL the test points whose .Mach = 0.8 or where .testpoint = 2?
I hope I have made it clear enough.

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 20 日
編集済み: Azzi Abdelmalek 2013 年 2 月 20 日

0 投票

idx=cellfun(@(x,y) x==2 |y==0.8,{Flight1.testpoint},{Flight1.match})
%idx is the index that fit your conditions

6 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 20 日
You can find the new struct vector
out=Flight1(idx)
Jay
Jay 2013 年 2 月 20 日
Thanks, but this applies to Flight1 data only. I have a directory which includes structure arrays for Flight1, Flight2,...,Flight5 and each of these contains at least 10 substructures (testpoints). I would like to scan the directory and plot the Data for the 2nd test point of each Flight.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 20 日
編集済み: Azzi Abdelmalek 2013 年 2 月 20 日
Your directory can't contain struct variables, but files! How are those variables stored? Unless they are stored in mat files with same names as variables
Jay
Jay 2013 年 2 月 20 日
yes they are stored in mat files (eg. Flight1.mat)
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 20 日
編集済み: Azzi Abdelmalek 2013 年 2 月 20 日
for k=1:10
s=sprintf('Flight%d',k)
Flight1=load(s)
idx=cellfun(@(x,y) x==2 |y==0.8,{Flight1.testpoint},{Flight1.match})
out=Flight1(idx)
v{k}={out.testpoint}
end
Jay
Jay 2013 年 2 月 20 日
Thanx. This seems to work.

サインインしてコメントする。

その他の回答 (1 件)

Thorsten
Thorsten 2013 年 2 月 20 日

0 投票

A = Flight([Flight.Mach] == 0.8);
B = Flight([Flight.testpoint] == 2);

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by