Matlab dictionary to map tuples of values to specific output

조회 수: 9(최근 30일)
Maxime Michel 2019년 3월 4일
답변: Sheng Chen 2019년 3월 4일
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.

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

답변(1개)

Sheng Chen 2019년 3월 4일
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

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

범주

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by