Matlab dictionary to map tuples of values to specific output

5 Ansichten (letzte 30 Tage)
Maxime Michel
Maxime Michel am 4 Mär. 2019
Beantwortet: Sheng Chen am 4 Mär. 2019
I have a set of data which maps phone frequencies to phone buttons (DTMF principle). It looks like the following:
What I have is a 2x10 matrix which contains associated frequencies which I would like to be able to map to the numbers of the above 'phone pad'. My data looks like this:
phoneNumber = [1336, 1209, 1336, 1477, 1209, 1336, 1477, 852, 1336, 1477; 941, 697, 697, 697, 770, 770, 1209, 852, 852];
What I would like to be able to do is map the set of 2 values in 'phoneNumber' (order should not be important!) which correspond to each column (column one would give (1336, 941)) and have this 'tuple' give the corresponding value from the above image.
Thanks in advance!

Antworten (1)

Sheng Chen
Sheng Chen am 4 Mär. 2019
Hi, the second row of phoneNumber matrix you gave has only 9 columns and I cannot find any pattern in your phoneNumber matrix.
So I assume that in both rows of phoneNumber matrix, the first column corresponds to the frequency of '0', the second column corresponds to the frequency of '1', ......... the 10th column corresponds to the frequence of '9'.
Then try this:
phoneNumber = [1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336,1477;
941, 697, 697, 697, 770, 770, 770, 852, 852, 852];
frequencyMap = containers.Map();
for number = 0 : 9
frequency = [phoneNumber(1, number + 1), phoneNumber(2, number + 1)];
frequencyMap(num2str(number)) = frequency;
end
disp(frequencyMap('0'));
disp(frequencyMap('3'));
disp(frequencyMap('9'));
The output is:
1336 941
1477 697
1477 852

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by