0
votes

I'm working on a structure with 12 fields, each consisting of a 1350x1 double. I want to delete all rows of all fields, given a condition regarding one of those fields, and come up with a new structure, still 12 field but of only 1150 rows.

I don't mind the change of index, since one of these fields is a "Time" field to index the others.

To clarify, my structure is called sens, and the fields are sens(1).Time, sens(1).Temp, sens(1).Humidity and so on. I want to find a value in sens(1).Time, define it as threshold value, and delete all rows smaller than this value, in all fields.

I know it's possible by going through all field names, but been looking for a faster way as the names of the fields and/or the structure vary.

Thank you.

1

1 Answers

0
votes

Check the structfun function from matlab and that should solve your problem. You have some examples that can help you with what you want, but in sum it should look something like this:

% A is your struct
% cond is the indexes of the rows you want to keep
A_clean= structfun(@(x) x(cond), A, 'UniformOutput', false)