No BSD License  

Highlights from
lookupTable

2.0

2.0 | 1 rating Rate this file 1 Download (last 30 days) File Size: 2.49 KB File ID: #19381

lookupTable

by Dan Cohn

 

30 Mar 2008 (Updated 31 Mar 2008)

Creates a lookup table for a collection of key/value pairs

| Watch this File

File Information
Description

Creates a lookup table for a collection of key/value pairs. Keys can be ANY data-type (although indexing over function handles might produce unexpected/incorrect behavior)
 
Examples:
 
weatherStruct = struct('clouds','rain','windy','cold');
obj = weatherObject(weatherStruct,...);
tbl = lookupTable('today''s weather', weatherStruct,obj,'found weather obj',0.0123,'random data here');
 
A = tbl('today''s weather')
  = weatherStruct
 
A = tbl(obj)
  = 'found weather obj'
 
A = tbl(0.0123)
  = 'random data here'
 
k = tbl.key(1) %equal to first element of key
  = 'today''s weather'
 
v = tbl.value(2) %equal to second element of value
  = 'found weather obj'

key = tbl.contents('-key')
    = {'today''s weather',obj,123}

value = tbl.contents('-value')
= {weatherStruct,'found weather obj','random data here'}

Acknowledgements
This submission has inspired the following:
dict
MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
25 Apr 2008 Dimitri Shvorob

5 minutes wasted trying to understand how it works.. The example in 'help' uses a user-defined class and so, of course, doesn't run; was the goal to make things more complicated? Finally, extra points for shadowing Simulink's 'lookuptable'.

25 Apr 2008 Dimitri Shvorob

Check out this submission:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6514&objectType=file

and search Matlab doc for

java.util.hashtable

Please login to add a comment or rating.
Updates
31 Mar 2008

Improved function help and code readability

Tag Activity for this File
Tag Applied By Date/Time
structures Dan Cohn 22 Oct 2008 09:55:47
cell arrays Dan Cohn 22 Oct 2008 09:55:47
lookup table Dan Cohn 22 Oct 2008 09:55:47
memoize Dan Cohn 22 Oct 2008 09:55:47
function handle Dan Cohn 22 Oct 2008 09:55:47
cellfun Dan Cohn 22 Oct 2008 09:55:47
data structure Dan Cohn 22 Oct 2008 09:55:47

Contact us at files@mathworks.com