


STRUCTINDEX Indexes each field in a structure of arrays.
STRUCTOUT = STRUCTINDEX(STRUCTIN, INDEX) takes a structure STRUCTIN
in which every field is a cell or numeric array and returns a
structure with the same fields with the data rearranged according to:
STRUCTOUT.FIELD1 = STRUCTIN.FIELD1(INDEX).

0001 function structure = structindex(structure, index) 0002 %STRUCTINDEX Indexes each field in a structure of arrays. 0003 % STRUCTOUT = STRUCTINDEX(STRUCTIN, INDEX) takes a structure STRUCTIN 0004 % in which every field is a cell or numeric array and returns a 0005 % structure with the same fields with the data rearranged according to: 0006 % STRUCTOUT.FIELD1 = STRUCTIN.FIELD1(INDEX). 0007 0008 fields = fieldnames(structure); 0009 for f = 1:length(fields) 0010 structure.(fields{f}) = structure.(fields{f})(index); 0011 end