Hi guys,
I am trying to write max() and min but our teacher said you cannot use max() and min() function. how can ı write alternativly these functions. I have done mean value like that:
if length(m)==4
element=element+1;
s =sum(m) / 4;
arc = [arc s];
m=[];
end
every 4 step m function reset and also values that have been in m (m has 4 element at the moment) sums and divide 4. the new value (mean value of a at the moment) goes arc.
I want to da that max and min version without max and min command but this time the values has to go new set that ı called maxvalues and min values could someone help me ?

3 件のコメント

Geoff Hayes
Geoff Hayes 2020 年 4 月 7 日
Ugur - if the idea is to write your own max function given an array of elements, then just think about how you would do this. Perhaps you would start with the first element in the array and compare it to the second element in the array. What comparison would you use? Which of the two would be kept to compare to the third element in the array? Try writing out the algorithm (on paper) before you start to code it up.Unless I'm misunderstanding what you are looking for, you won't need to sum up any elements like in the code you've shown above...
Ugur Sahin
Ugur Sahin 2020 年 4 月 7 日
https://imgur.com/a/wjWhlTQ
Image Analyst
Image Analyst 2020 年 4 月 7 日
Ugur, post the image directly here with the green and brown frame icon, not on some third party web site.

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

 採用された回答

David Hill
David Hill 2020 年 4 月 7 日

0 投票

a=sort(x)
maxvalue=a(end);
minvalue=a(1);

3 件のコメント

Ugur Sahin
Ugur Sahin 2020 年 4 月 7 日
sorry sort function prohibited too.
David Hill
David Hill 2020 年 4 月 7 日
maxvalue=x(1);
minvalue=x(1);
for k=2:length(x)
if x(k)>maxvalue
maxvalue=x(k);
elseif x(k)<minvalue
minvalue=x(k);
end
end
Ugur Sahin
Ugur Sahin 2020 年 4 月 7 日
thank you so much :D

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEquations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by