How can i solve this exam practise question

5 ビュー (過去 30 日間)
Comfort
Comfort 2020 年 6 月 11 日
コメント済み: Rena Berman 2020 年 10 月 12 日
  5 件のコメント
Rik
Rik 2020 年 6 月 14 日
(original question and comments by Comfort Chauke (the name of OP before it was changed to Wilson) recovered from Google cache)
Comfort Chauke on 11 Jun 2020 at 9:39:
How can i solve this exam practise question
Comfort Chauke on 11 Jun 2020 at 10:33:
function [minsum, maxsum]=MyFunction(L)
sum=0;
for i=1:length (L)
sum=sum+L(i);
end
min=L(1);
max=L(1);
for i=1:length (L)
if L(i)<min
min=L(i);
end
if L(i)>max
max=L(i);
end
end
minsum=sum-max
maxsum=sum-min
Comfort Chauke on 11 Jun 2020 at 12:03:
That's my problem i don't know how make calculate the minimum and maximum values that can be obtained from adding K elements
Rena Berman
Rena Berman 2020 年 10 月 12 日
(Answers Dev) Restored edit

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

採用された回答

Rik
Rik 2020 年 6 月 11 日
Since you aren't allowed to use efficient tools (e.g. sort), you are forced to write slow code. I would not try to use eval to cheat here, although I doubt the grader will detect that, especially if you encapsulate it in str2func.
BUT: you are in luck. You were given the task to get the numbers without repitition. The unique function will automatically sort the output for you.
  16 件のコメント
Comfort
Comfort 2020 年 6 月 12 日
Alright....Thank you so much
Rik
Rik 2020 年 6 月 12 日
You're welcome. If you feel I have solved your question, please consider marking my answer as accepted answer. If not, feel free to comment with your remaining issues.

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 6 月 11 日
編集済み: madhan ravi 2020 年 6 月 11 日
doc mink
doc maxk
doc sum
  2 件のコメント
Rik
Rik 2020 年 6 月 11 日
Since this question is supposed to be run in Octave, the students are forced to use other functions, since mink and maxk were introduced in R2017b, but aren't implemented in Octave.
madhan ravi
madhan ravi 2020 年 6 月 11 日
Aha thanks Rik , didn't know that.

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by