I have a struct array: a 1x10 struct array with fields: N, t, q, r, T, each of which is a vector of type double
.
The 10 array entries each represent the outcome of a testing condition in an experiment. I would like to be able to make a function that takes two indices, index1
and index2
, and modifies the constituent N, t, q, r vectors (T is a single number) so that they become length index1
:index2
. Something like
function sa = modifier(struct_array, index1, index2)
sa = structfun(@(x) x(index1:index2), struct_array, 'UniformOutput', false)
stuff
end
Now, where stuff
is, I've tried using structfun
and cellfun
, see here except that those return a struct and a cell array, respectively, whereas I need to return a struct array.
The purpose of this is to be able to get certain sections of the experimental results, e.g. maybe the first five entries in each vector inside each cell correspond to the initial cycles of the experiment.
Please let me know if this is possible, and how I might go about it!