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.

Antworten (1)

Walter Roberson
Walter Roberson am 29 Apr. 2018

0 Stimmen

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.

Kategorien

Produkte

Gefragt:

am 29 Apr. 2018

Beantwortet:

am 29 Apr. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by