matlab - Perform action on all fields of structure -
i wonder if it's possible perform action on all fields of structure @ once?
my scenario:
i have data eye tracker device. stored in struct data
, , has following fields:
data.positionx data.positiony data.velocity data.acceleration
each field contains vector of integers. suppose want delete sample number 10 data stream. have following:
data.positionx(10) = []; data.positiony(10) = []; data.velocity(10) = []; data.acceleration(10) = [];
how more efficiently?
yes, use dynamic field names.
fields = fieldnames(data); i=1:length(fields) field = fields{i}; data.(field)(10) = []; end
Comments
Post a Comment