index = data.temperature > 300;
data2.time = data.time(index);
data2.temperature = data.temperature(index);
data2.length = data.length(index);
Maybe you want it more general:
function T = IndexedStructCopy(S, Condition, FieldList)
if nargin == 2
FieldList = fieldnames(S);
end
for iField = 1:numel(FieldList)
Field = FieldList{iFile};
T.(Field) = S.(Field)(Condition);
end
end
Call this like:
data2 = IndexedStructCopy(data, data.temperature > 300)
or perhaps:
data2 = IndexedStructCopy(data, data.temperature > 300, ...
{'time', 'temperature', 'length'})
Best Answer