5.0

5.0 | 2 ratings Rate this file 6 Downloads (last 30 days) File Size: 2.87 KB File ID: #19484

Flexible search and listing tool for field names in a structure array

by Paul A.M. Bune

 

07 Apr 2008 (Updated 03 Jun 2008)

Searches for field names in a structure array and lists them

| Watch this File

File Information
Description

Call options:
------------

SearchFields(AStruct)
- Displays all fields in structure array AStruct with their complete ("long") names.

SearchFields(AStruct, SearchString)
- Displays all fields in structure array AStruct of which the name contains SearchString (default = case-insensitive).

SearchFields(AStruct, SearchString, SearchOption)
- The following options may be indicated by SearchOption:
  'default' - Default (case-insensitive search, see above).
  'case' - Case-sensitive search.
  'exact' - Only those field names are listed which matches the SearchString exactly (case-insensitive search).
  'exactcase' - The same as 'exact', but with case-sensitive search.
  'begin' - Only those field names are listed of which the beginning matches the SearchString (case-insensitive search).
  'begincase' - The same as 'begin', but with case-sensitive search.
  'end' - Only those field names are listed of which the end matches the SearchString (case-insensitive search).
  'endcase' - The same as 'end', but with case-sensitive search.
  If no option is given, 'default' is assumed.

SearchFields(AStruct, SearchString, SearchOption, AStructName)
- Normally, the name of the structure array AStruct is resolved using the internal MatLab function "inputname". However, this does not work when the name of AStruct contains dots and/or brackets. As a workaround (as well as to enable recursive operation) the name of AStruct can be entered "manually" as a string in AStructName.

FoundFieldsList = SearchFields(AStruct, ...)
- A list of the found field names is stored as a cellular string array into the output variable FoundFieldsList.

If no output variable is indicated, the names are printed as a list on the screen.

Example of function call:
------------------------
SearchFields(ExampleStruct, 'afield')

Result (example):
----------------
ExampleStruct.AField
ExampleStruct.AnotherField{2,3}.AField
ExampleStruct.AnotherField{2,3}.AField2

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
11 May 2008 Makoto Miyakoshi

Nice tool. Good job.

19 Apr 2012 Andrew Davis

Very useful

Please login to add a comment or rating.
Updates
03 Jun 2008

No change in the program file. Only correction of a small typo in the description on the website, where the search mode using the 'default' option was indicated as being case-sensitive, while in realitiy it is case-insensitive.

Tag Activity for this File
Tag Applied By Date/Time
structures Paul A.M. Bune 22 Oct 2008 09:56:39
cell arrays Paul A.M. Bune 22 Oct 2008 09:56:39
search Paul A.M. Bune 22 Oct 2008 09:56:39
list Paul A.M. Bune 22 Oct 2008 09:56:39
field names Paul A.M. Bune 22 Oct 2008 09:56:39
structure array Paul A.M. Bune 22 Oct 2008 09:56:39

Contact us at files@mathworks.com