keepfield

Keep specified fields of a structure, discarding other fields.

You are now following this Submission

ML provides a useful function RMFIELD to remove specified field(s) from a structure, but no corresponding function to KEEP specified field(s), removing the rest. This function addresses that discrepancy.

ex.:
a = dir('*.m');
b = keepfield(a,{'name','date'});

This is an exceptionally short but useful piece of code.

Cite As

Brett Shoelson (2026). keepfield (https://se.mathworks.com/matlabcentral/fileexchange/7031-keepfield), MATLAB Central File Exchange. Retrieved .

Acknowledgements

Inspired by: keep

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0