loop over struct element

Suppose I create a struct
data.ID0 data.ID1
Suppose I want to have a loop i that first work with data.IDO and then with data.ID1. Please advise.

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 29 日

0 投票

structfun(). If the results are scalar numeric values and what you want is an array of the results, then do not use the 'uniform', 0 option. Otherwise use 'uniform', 0, which will cause a struct to be returned with fields the same as the original field names, but with content as generated by the function you specified.
Example:
structfun(@mean2, data) %mean2 always returns a scalar even for empty input
structfun(@tan, data, 'uniform', 0) %returns struct with fields ID0 and ID1 in which each value has been replaced by its tan.

カテゴリ

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

製品

タグ

質問済み:

2018 年 4 月 29 日

回答済み:

2018 年 4 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by