vector - Mean of fields in a structure using structfun, Matlab -
i have structure in following format:
a.l1.data = <1000x3 double> a.l2.data = <1000x3 double> a.l3.data = <1000x3 double>
i obtain mean of first column of fields, i.e. 1 vector of 1000 rows mean of l1, l2 , l3.
i have tried using structfun following code:
foo = structfun(@(x) mean(x.data(:,1)), a, 'uniformoutput', false)
however, gives me mean (single value) of each first column rather mean of fields.
if do:
foo = structfun(@(x) mean(x.data), a, 'uniformoutput', false)
i obtain mean of each column each field.
how should modify code?
you can access data of struct struct2array
.
get struct firstcolumnsofdata
fields l1
l2
l3
first columns of data
:
firstcolumnsofdata = structfun(@(x) x.data(:,1), a, 'uniformoutput', false)
get mean of each element of l1
l2
l3
:
ml123 = mean(struct2array(firstcolumnsofdata')) % transpose not mean of each field
Comments
Post a Comment