MATLAB: Deleting the same rows from every field of a structure

columncolumnsdeleteeveryfieldMATLABremoverowrowssamestructstructure

I have a structure as follows : 
 
s.f1 = [27; 31; 43; 56; 60; 76; 87; 95];
s.f2 = [28; 32; 46; 54; 65; 70; 85; 98];
s.f3 = [29; 36; 43; 58; 68; 79; 84; 93];
s.f4 = [21; 82; 44; 57; 66; 78; 82; 97];
s.f5 = [22; 92; 48; 53; 64; 77; 83; 99];
s.f6 = [23; 38; 43; 52; 61; 75; 81; 91];
s.f7 = [24; 39; 40; 51; 62; 76; 80; 92];
I want to delete, say, the 4th and 5th rows from every field of this structure. How do I accomplish this? 

Best Answer

This can be accomplished by the use of the "structfun" function along with the "removerows" function as follows : 
 
>> rows_to_remove = [4 5]; %vector of row indices you want to remove
>> struct_new = structfun(@(x) (removerows(x, 'ind', rows_to_remove)), s, 'UniformOutput', false);
The new structure "struct_new" now contains the fields without the 4th and 5th rows.