How to apply a function to all rows of a field in a structure?
5 views (last 30 days)
Show older comments
In my script a structure's field is created the following way:
omleszt(1).N = length(omleszt(1).out);
omleszt(2).N = length(omleszt(2).out);
omleszt(3).N = length(omleszt(3).out);
omleszt(4).N = length(omleszt(4).out);
And the same goes on with many other fields of omleszt. Because of this writing the script became a tedious and long task. Is there a way to apply the function to all the rows of a field with a single command? Like for example (I know this does not work):
omleszt.N = length(omleszt.out)
0 Comments
Accepted Answer
Walter Roberson
on 8 Jan 2016
T = cellfun(@length, {omleszt.out}, 'Uniform', 0);
[omlestzt.N] = T{:};
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!