user2578152
user2578152

Reputation:

how can I vectorize an operation on a structure in Matlab?

I have a structure that has several fields each containing a vector of numbers that I want to take their average without a for looping each field ,

a.a=[1 2 3 4 5]
a.b=[4 5 6 7 8 9];
a.c=[23 23 3 3 ];
...

how can I vectorize that ?

Upvotes: 2

Views: 61

Answers (1)

bla
bla

Reputation: 26069

you can use structfun for that, for example:

result = structfun(@mean,a)

Upvotes: 4

Related Questions