Accessing values from struct array

I have a giant struct array with fields: f1, f2, f3. i.e. Struct Array: StAr(i) has StAr(i).f1, StAr(i).f2,StAr(i).f3. But I want to create a new Array by just collecting all the f1 values without using a for loop. How do I achieve this?
Thanks guys

 採用された回答

Matt J
Matt J 2012 年 10 月 15 日

0 投票

newArray=[StAr.f1];

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 10 月 15 日
編集済み: Wayne King 2012 年 10 月 15 日

0 投票

data = getfield(structarrayname,'f1');
For example:
mystruct = struct('f1',randn(100,1),'f2',randn(100,1),'f3',randn(100,1));
data = getfield(mystruct,'f1');

1 件のコメント

Sam Da
Sam Da 2012 年 10 月 15 日
Thanks to you as well but the next answer is simpler I guess.

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

カテゴリ

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

タグ

質問済み:

2012 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by