Creating the sounds of a touchtone keypad

7 views (last 30 days)
Mark Grano
Mark Grano on 26 Oct 2012
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!

Answers (2)

Star Strider
Star Strider on 26 Oct 2012
Edited: Star Strider on 26 Oct 2012
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 Comments
Matt Fig
Matt Fig on 27 Oct 2012
I feel your pain, SS. You just gotta love duplicate questions and OP's who don't let you know...
Star Strider
Star Strider on 27 Oct 2012
Edited: Star Strider on 27 Oct 2012
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.

Sign in to comment.


Walter Roberson
Walter Roberson on 26 Oct 2012
Are you looking for length(stra) ?
  3 Comments
Mark Grano
Mark Grano on 26 Oct 2012
is it possible to convert the string into an array?
Walter Roberson
Walter Roberson on 26 Oct 2012
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.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!