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");
if (isempty(stra(k)) = 0)
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!
No products are associated with this question.
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.