I would like to map numeric output from a matrix to a string.
Given
compute=[ 7, 4, 3; 3, 4, 7]
how can one obtain a string mappin
MATLAB has a Map container type that makes this very straighftorward:
keySet = [7, 4, 3];
valSet = {'Run', 'Walk', 'Jog'};
map = containers.Map(keySet,valSet);
Get the requested values:
>> vals = values(map,num2cell(compute))
vals =
'Run' 'Walk' 'Jog'
'Jog' 'Walk' 'Run'
This is a class after all, so you can also use a more familiar OOP syntax for calling the values method:
>> vals = map.values(num2cell(compute))
vals =
'Run' 'Walk' 'Jog'
'Jog' 'Walk' 'Run'