ENUMARRAY
ENUMARRAY inherits from class double, but allows a user to index into the array using enumerated indices (i.e. strings) rather than numerical indices. Inputs are the array data, an MxNxPx... double array containing the data, and cell arrays of strings used to index into the data.
The created object can be referenced using strings or numeric indices.
Comments and reports of bugs are welcome.
Example:
data = repmat((1:10)',1,6) + repmat([10 20 30 40 50 60],10,1);
ind1 = {'one','two','three','four','five','six','seven','eight','nine','ten'};
ind2 = {'red','orange','yellow','green','blue','purple'};
EA = enumarray(data,ind1,ind2)
EA('one','red')
ans =
11
See the comments for more detailed examples. Note that due to the use of OOP, the earliest version of MATLAB for which this works is R2008a.
Cite As
Jen (2024). ENUMARRAY (https://www.mathworks.com/matlabcentral/fileexchange/21488-enumarray), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Language Fundamentals > Data Types > Numeric Types >
- MATLAB > Language Fundamentals > Matrices and Arrays > Matrix Indexing >
Tags
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.