min(Midterms) returns the value of the minimum, not the location of the minimum. You should do
[~, minidx] = min(Midterms);
Midterms(minidx) = [];
Note, by the way, that you of code of the form
if first condition;
do first something
else second condition
do second something
end
What this means to MATLAB is the same as
test first condition without displaying any result because "if" just doesn't
display the results of the condition no matter if ";" is there or not
if first condition was all true
do first something
display result of doing first something because there was no ";" at the end
of the calculation
otherwise
test second condition as an expression, because it is *not* in an "if" or "while" case
display result of testing second condition, because it was just a line of code and
there was no semi-colon to say not to display
throw away result of testing second condition because it was just a line of code, not an if or while
do second something
display result of doing second something because there was no ";" at the end of
the calculation
end
... All of which is a long way to point out that if you only want "do second something" to be done if the second condition is true, then what you need is an "elseif" rather than an "else".
However you make it an "elseif" then consider: what should you do if neither the first condition nor the second condition is true? In MATLAB it is possible for neither to be true: for example if the values were all NaN.
Best Answer