write a three_max function
古いコメントを表示
* not a homework question. This is a practice question for an upcoming exam
Write a function, three_max, which takes three numbers, x1, x2, x3 and outputs the largest number. Do this without using the variety of built-in functions associated with max and sort. Test it.
I have created a function but when ever I try to test it I get a "not enough input arguments" for line 2: if (x1>x2 && x1>x3). I do not know what I am doing wrong
function three_max(x1,x2,x3)
if (x1>x2 && x1>x3)
max=x1;
elseif (x2>x1 && x2>x3)
max=x2;
elseif (x3>x1 && x3>x1)
max=x3;
end
end
1 件のコメント
Thanishq
2023 年 10 月 26 日
hii
this is the program i did :
function [p] = three_max(a,b,c)
if a>b && a>c
p=a;
elseif b>a && b>c
p=b;
else
p=c;
end
As u have this problem:"I have created a function but when ever I try to test it I get a "not enough input arguments" for line 2: if (x1>x2 && x1>x3). I do not know what I am doing wrong "
after writing the code we just simply click run button but in command prompt we have to write this....
>> three_max(1,2,3)
ans =
3
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!