我想想看看在matlab中连接map和struct之后会得到什么,比如让我们考虑一下Map Container
ticketMap = containers.Map(...
{'2R175', 'B7398', 'A479GY', 'NZ1452'}, ...
{'James Enright', 'Carl Haynes', 'Sarah Latham', ...
'Bradley Reid'});
这张地图的键/值结构对我来说很清楚,现在让我们假设我们有以下结构
s1.ticketNum = '2S185'; s1.destination = 'Barbados';
s1.reserved = '06-May-2008'; s1.origin = 'La Guardia';
s2.ticketNum = '947F4'; s2.destination = 'St. John';
s2.reserved = '14-Apr-2008'; s2.origin = 'Oakland';
s3.ticketNum = 'A479GY'; s3.destination = 'St. Lucia';
s3.reserved = '28-Mar-2008'; s3.origin = 'JFK';
s4.ticketNum = 'B7398'; s4.destination = 'Granada';
s4.reserved = '30-Apr-2008'; s4.origin = 'JFK';
s5.ticketNum = 'NZ1452'; s5.destination = 'Aruba';
s5.reserved = '01-May-2008'; s5.origin = 'Denver';
我们有5个不同字段的结构,现在遵循命令
seatingMap = containers.Map( ...
{'23F', '15C', '15B', '09C', '12D'}, ...
{s5, s1, s3, s4, s2});
对我有意义,因为例如使用键23F我可以访问s1结构的字段,例如
>> seatingMap('23F').origin
ans =
'Denver'
所有这些部分对我来说都很清楚,现在一起使用ticketMap和seatingMap,你可以找到预留座位15B的人的名字 ticket = seatingMap('15B')。ticketNum; passenger = ticketMap(ticket)
但这是最佳方式吗?先谢谢