integers to English phrase
Afficher commentaires plus anciens
I am trying to create a function that converts double digits between 21 and 39 into its english phrase.
I think I have the beginning of the code that sets the integer parameter but I do not know what to do next. This is what I have so far:
function S = Convert_to_words(number)
ones = {'', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'};
tens = {'', '', 'ERROR', 'Twenty', 'Thirty'};
end
10 commentaires
Walter Roberson
le 15 Nov 2019
[tens{tens_digit+1}, ones{ones_digit+1}]
Britnie Casillas
le 15 Nov 2019
Britnie Casillas
le 15 Nov 2019
Well, one problem is that Walter's advice was based on your initial code where tens and ones were (a) provided by you and (b) equal to lists of string that you've now renamed to something else.
ones= {'', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'};
tens = {'', '', 'ERROR', 'Twenty', 'Thirty'};
In your latest code however, tens and ones are no longer provided, but you still try to use them the same way as in Walter's suggestion. Another problem is that you are not using the input variable number anywhere.
Britnie Casillas
le 15 Nov 2019
Britnie Casillas
le 15 Nov 2019
Matt J
le 16 Nov 2019
Well, the error message is telling you the problem. You haven't created the variables tens_digits or one_digits. You were supposed to derive them from number. That was the piece of your homework that Walter left for you to do.
Britnie Casillas
le 16 Nov 2019
Stephen23
le 16 Nov 2019
"wouldnt the tens_digits and one_digits be the same variables as the ones and tens? "
No.
tens ans ones are cell arrays of character vectors.
tens_digits and one_digits should be numeric values of the digits in the given number (which by adding one to (because MATLAB indexing starts from one) can be used as indices into ones and tens).
"What do you mean derive them from number? "
You need to get the digits from number, as numeric values.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!