Write a function largest () such that it can accept multiple numbers and return the largest item from the given list.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Write a function largest () such that it can accept multiple numbers and return the largest item from the given list.
3 commentaires
Réponses (1)
Jon
le 27 Juil 2022
There is already a MATLAB function that "can accept multiple numbers and return the largest one"
x = [2,15,23.7,91.4,80.3] % vector with multiple numbers
xmax = max(x) % return the largest one
2 commentaires
Jon
le 27 Juil 2022
if you need to promt the user for the list then you can do something like this:
x = input('enter list of numbers, for example [1.1,2.3,38.7,5.3] ')
dpb
le 27 Juil 2022
Most homework assignments (as this must surely be) preclude the use of builtin functions to solve the problem as the pegagical exercise for the student...and, it's not clear the intent of this exercise is to consider a vector of multiple values as "multiple inputs" or not -- my reading is "not", but it doesn't say so unequivocally, granted.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!