Hi all,
I'm trying to generate an anonymous function where I pass in an array of structures and convert it to a structure of arrays (possibly offsetting the indices for each of the inputs). I've been doing it so far using an anonymous function, but I'm trying to figure out how to generalize it.
Here's what I've got so far:
Sync = @(x,fna) [x(1).(fna)(shape_params.indices{1}),...
x(2).(fna)(shape_params.indices{2})];
So when I call it I give it the array of structures (x), and the field name (fna) that I want to create the output array of. shape_param.indices is a cell array that tells me which entries I want from each of the entries in the array of structs.
For example:
XX(1).a = (1:10)';
XX(2).a = (2:11)';
shape_params.indices{1} = (2:5)';
shape_params.indices{2} = (1:4)';
YY.a = Sync(XX,'a')
should give me:
YY.a = [2,2;3,3;4,4;5,5];
I can define Sync to accomodate the number of entries in XX by just creating a switch. But now I need to generalize it, since I don't want to make a switch statement that has up to 16 varieties.
Any suggestions on how I can do it, for an unknown number of vectors that I'm combining?
Thanks, Dan