keepfield
Version 1.0.0.0 (1.4 KB) by
Brett Shoelson
Keep specified fields of a structure, discarding other fields.
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://uk.mathworks.com/matlabcentral/fileexchange/7031-keepfield), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R14SP1
Compatible with any release
Platform Compatibility
Windows macOS LinuxCategories
Find more on Structures in Help Center and MATLAB Answers
Tags
Acknowledgements
Inspired by: keep
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 |
