Map fields of a structure to output variables

バージョン 1.2.0.0 (553 Bytes) 作成者: Hoi Wong
The program assigns each field of a structure into output arguments.
ダウンロード: 985
更新 2009/3/30

ライセンスがありません

This is made in response to one of the comments in:
http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/

The program assigns each field of a structure into output arguments.

s =
a: 1
b: [1 2 4]
c: [5x2 double]
d: 'test'
e: {[3]}

>> [a b c d e]=struct2vars(s)

a =
1

b =
1 2 4

c =
0.8147 0.0975
0.9058 0.2785
0.1270 0.5469
0.9134 0.9575
0.6324 0.9649

d =
test

e =
[3]

A even better usage if you're trying to dump all your struct into the current workspace:
T=fieldnames(S);
[T{:}]=struct2vars(S);

引用

Hoi Wong (2024). Map fields of a structure to output variables (https://www.mathworks.com/matlabcentral/fileexchange/23254-map-fields-of-a-structure-to-output-variables), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2007b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.2.0.0

Added this usage case in comments file:

T=fieldnames(S);
[T{:}]=struct2vars(S);

1.1.0.0

Modified tag to be more sensible. I mistakenly tagged it with a URL

1.0.0.0