How to implement Look Up Table function with cells

조회 수: 4 (최근 30일)
Miguel
Miguel 2016년 2월 26일
댓글: Miguel 2016년 3월 2일
Hello,
I want to create a Look Up Table using cells. This can be better illustrated with an example.
I have a cell of string values c = {'1','3'} that are part of an alphabet b = {'5','3','1'}. This alphabet maps to a = {'E10','E11','E12'}.
The order is important here so I want the mapping '5' -> 'E10', '3' -> 'E11' and '1' -> 'E12'.
I am expecting the output to be 'E12', 'E11'.
How do you think I can do this? Thanks in advance!!

채택된 답변

Stephen23
Stephen23 2016년 2월 26일
This is easy via a containers.Map object:
>> a = {'E10','E11','E12'};
>> b = { '5', '3', '1'};
>> obj = containers.Map(b,a);
and accessing the values is easy:
>> obj('3') % one value
ans =
E11
>> values(obj,{'1','3'}) % multiple values.
ans =
'E12' 'E11'
  댓글 수: 1
Miguel
Miguel 2016년 3월 2일
Thanks a lot for the answer! That way is much simpler than the one I found!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Marine and Underwater Vehicles에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by