Search a Structure Array or Database
Version 1.0.0 (1.95 KB) by
Derek Wood
Searches an entire database structure for the given values or strings, and returns corresponding indices of matching entries
A flexible tool capable of searching a large structure array for matching numerical or character values.
Use case:
[ index_array ] = searchDatabase( dataBase, value, fieldName, modifier)
Required Inputs:
dataBase (struct array or matrix) : struct database to search
value (char or double(value or list) ) : Value/string of fieldname desired to search for or match to
String input is case-insensitive. By default, searches for partial matches to strings.
Optional Inputs:
fieldName (string) : Fieldname of database to searach within (case-insensitive). Default value is an empty string.
If a value is given, will only search for matches in struct fields matching the given fieldName.
modifier (char) : Has 5 allowable values; '=', '~', '>', '<', and '' (empty string). The function varies based on class of value:
If value is a char or string:
1. '': case-insensitive search for value as substring of database field value (default for strings)
2. '=': case-insensitive search for value as exact, full-string match to database field value
3. '~': case-insensitive search for absence of value as substring of database field value
If value is a double:
1. '=': value must be equal to database field value (default value for double)
2. '<': value must be greater than database field value
3. '>': value must be less than database field value
4. '~': value must not be equal to database field value
Output is a list of indices corresponding to the entries in the database matching the criteria supplied by the inputs.
If dataBase is a 2D array (or higher dimensionality), this tool will still return the correct result, however to convert to the full index array you will need to use matlab's ind2sub function.
Cite As
Derek Wood (2024). Search a Structure Array or Database (https://www.mathworks.com/matlabcentral/fileexchange/112915-search-a-structure-array-or-database), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2022a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |