4.0

4.0 | 1 rating Rate this file 130 downloads (last 30 days) File Size: 1.4 KB File ID: #7031

keepfield

by Brett Shoelson

 

01 Mar 2005 (Updated 03 Mar 2005)

Code covered by BSD License  

Keep specified fields of a structure, discarding other fields.

Download Now | Watch this File

File Information
Description

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.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
keep

MATLAB release MATLAB 7.0.1 (R14SP1)
Other requirements Tested in ver 6.01 and ver 7.04 sp2.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
15 Mar 2006 Omer Demirkaya

Saved my time! This is exactly what I needed.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
structures Brett Shoelson 22 Oct 2008 07:42:27
cell arrays Brett Shoelson 22 Oct 2008 07:42:27
keep Brett Shoelson 22 Oct 2008 07:42:27
field Brett Shoelson 22 Oct 2008 07:42:27
structure Brett Shoelson 22 Oct 2008 07:42:27
rmfield Brett Shoelson 22 Oct 2008 07:42:27
utilities Brett Shoelson 22 Oct 2008 07:42:27
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com