Write a function largest () such that it can accept multiple numbers and return the largest item from the given list.

1 回表示 (過去 30 日間)
Hania
Hania 2022 年 7 月 27 日
コメント済み: dpb 2022 年 7 月 27 日
Write a function largest () such that it can accept multiple numbers and return the largest item from the given list.
  3 件のコメント
Hania
Hania 2022 年 7 月 27 日
I JUST DONT KNOW HOW TO GET MULTIPLE INPUTS
dpb
dpb 2022 年 7 月 27 日
See syntax @<@doc:function> shows how...although none of the examples use more than one, the syntax is shown in general.
To be really neat and (probably) get extra credit, you might look at @<nargin> and @<varargin> as well...
Just dive in...

サインインしてコメントする。

回答 (1 件)

Jon
Jon 2022 年 7 月 27 日
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
x = 1×5
2.0000 15.0000 23.7000 91.4000 80.3000
xmax = max(x) % return the largest one
xmax = 91.4000
  2 件のコメント
Jon
Jon 2022 年 7 月 27 日
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
dpb 2022 年 7 月 27 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by