title: Is there a way to remove all but a few desired fields from a struct in MATLAB?
body: <p>So I have several structs that contains data that is used is a dozen or so scripts. The problem is that for each script I only need a handfull of variables and the rest I can ignore. I am using a massive amount of data (gigs of data) and MATLAB often gives me out of memory errors so I need to remove all unnecessary fields from the structs.</p>
  
  <p>Currently I have a cell that contains all unneeded fields and then I call rmfield on the structs. But the fields in the structs often change and it is getting to be a pain to be constantly updating the list of unneeded fields. So is there a way to tell MATLAB to keep only those fields I want and remove everything else even if I don't know what everything else is?</p>
  
  <p>Here is an example,</p>
  
  <ul>
  <li>Struct 1 has: A, B, C, D, E fields </li>
  <li>Struct 2 has: A, B, C, D, E, F fields</li>
  <li>Struct 3 has: A, B, C, D, E, F, G, H, I fields</li>
  </ul>
  
  <p>Sometimes Struct 3 might only have A thru G.</p>
  
  <p>I want to keep only A, B, and C fields and remove all other data from all the structs.</p>