MATLAB COMPILER RELEASE NOTES User's Guide Page 433

  • Download
  • Add to my manuals
  • Print
  • Page
    / 716
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 432
Programming Fundamentals
17-25
Programming Fundamentals
Fast Key Lookup Provided with New Map Data Structure
This release introduces a new MATLAB class called a Map. An object of the Map class is
an array of any MATLAB data type that supports lookup table functionality. Unlike most
arrays in MATLAB that only allow access to the elements by means of integer indices,
indices for Map containers can be nearly any scalar numeric value or a character string.
The following example creates a Map object that is an array of strings. It is very much
like any other string array except that with each value of this array there is also a lookup
key associated with it. This particular Map contains the names of capital cities in the
United States. These are the values of the Map object. Associated with each capital city
value is the US state that it resides in. These are the keys of the Map object. You look
up values in the Map using key indices. Call the containers.Map constructor to create an
array of six capital cities indexed by six US states. (The capital of Alaska has purposely
been entered incorrectly):
US_Capitals = containers.Map( ...
{'Arizona', 'Nebraska', 'Nevada', ... % 6 States
'New York', 'Georgia', 'Alaska'}, ...
{'Phoenix', 'Lincoln', 'Carson City', ... % 6 Capitals
'Albany', 'Atlanta', 'Fairbanks'});
Show the capitals of three of the states by looking them up in the Map using the string
indices 'Nevada', 'Alaska' and 'Georgia':
values(US_Capitals, {'Nevada', 'Alaska', 'Georgia'})
ans =
'Carson City' 'Fairbanks' 'Atlanta'
Correct the capital city of Alaska by overwriting the entry at string index 'Alaska':
US_Capitals('Alaska') = 'Juneau';
US_Capitals('Alaska')
ans =
Juneau
The term containers.Map refers to a Map class that is part of a MATLAB package
called containers. For more information, see Map Containers in the Programming
Fundamentals documentation.
Page view 432
1 2 ... 428 429 430 431 432 433 434 435 436 437 438 ... 715 716

Comments to this Manuals

No comments