Creating the sounds of a touchtone keypad

조회 수: 4 (최근 30일)
Mark Grano
Mark Grano 2012년 10월 26일
Hello, im working on a project that produces the sound of a keypad when you enter a phone number.
i need help distinguishing between characters and digits and making sure the user entered a ten digit phone number. I know i need to use the function isempty() but i am not sure how to fully use the function. What i have for this part is the following:
stra= input("Enter a ten digit phone number");
cnt=0; k=1;
while (k<20);
str2num(stra(k));
if (isempty(stra(k)) = 0)
cnt= cnt+1;
i am fairly certain im using isempty() incorrectly. and im actually not even sure if im on the right track. but none the less any help would be appreciated greatly. Thanks!

답변 (2개)

Star Strider
Star Strider 2012년 10월 26일
편집: Star Strider 2012년 10월 26일
I'm not certain I understand where you are in your project, but you probably don't need isempty. I suggest for a start to consider these:
% Read phone numnber in as a string:
stra = input('Enter a ten digit phone number: ', 's')
% Find any letters:
ltrs = regexpi(stra, '[A-Z]\w*')
You'll need to fill in whatever logic you require here either to be sure your stra variable contains all numbers (the input function will throw an error if any letters are entered, so you have to add the 's' argument to input to allow for letters), or to convert the letters to their keypad numeric equivalents if that is what you want to do.
% Convert all-number string phone number to a numeric vector:
for k1 = 1:10
phnr(k1,:) = str2double(strphnr(k1));
end
To output the keypad tones once you have generated them, see sound and its related functions.
  댓글 수: 12
Matt Fig
Matt Fig 2012년 10월 27일
I feel your pain, SS. You just gotta love duplicate questions and OP's who don't let you know...
Star Strider
Star Strider 2012년 10월 27일
편집: Star Strider 2012년 10월 27일
Thank you Matt. I kept it open for several hours waiting for a reply, and when I didn't get one, figured it would wait until morning.
I appreciate your sympathies!
I'm not willing to stoop to ‘Thank you for formally accepting my answer’, but when the OP says ‘wow that worked great! Thank you so much.’ and doesn't accept it, it's difficult not to feel a bit betrayed.

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


Walter Roberson
Walter Roberson 2012년 10월 26일
Are you looking for length(stra) ?
  댓글 수: 3
Mark Grano
Mark Grano 2012년 10월 26일
is it possible to convert the string into an array?
Walter Roberson
Walter Roberson 2012년 10월 26일
Notice that input() by default is numeric input, so unless the user specifically encloses their response in '' then you get back one number rather than a string of numbers. Star Strider showed the change to have input() read strings, by using the 's' option.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by