Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Одиноков / МиИПиС_асп_13г / MATLAB_R2013a_Выбор.doc
Скачиваний:
30
Добавлен:
15.04.2015
Размер:
4.03 Mб
Скачать

Mapping to a Cell Array

As with structures, you can also map to a cell array in a Map object. Continuing with the airline example of the previous sections, some of the passengers on the flight have "frequent flyer" accounts with the airline. Map the names of these passengers to records of the number of miles they have used and the number of miles they still have available:

accountMap = containers.Map( ...

{'Susan Spera','Carl Haynes','Anna Latham'}, ...

{{247.5, 56.1}, {0, 1342.9}, {24.6, 314.7}});

Use the Map to retrieve account information on the passengers:

name = 'Carl Haynes';

acct = accountMap(name);

fprintf('%s has used %.1f miles on his/her account,\n', ...

name, acct{1})

fprintf(' and has %.1f miles remaining.\n', acct{2})

Carl Haynes has used 0.0 miles on his/her account,

and has 1342.9 miles remaining.