Help with conditional statements

1 view (last 30 days)
Marcel
Marcel on 23 Apr 2014
Commented: Image Analyst on 24 Apr 2014
Dear all,
I am new to matlab and I am trying to solve the following question... I already tried the help function and google, but I am kind of stuck. The question is: A student passes the exam if the grade on each of the four tests is greater or equal to 6. If this requirement is not met (that is, at least one of the four tests was graded with 5 or less), the student can pass the exam, performing an additional resit test, if the average score (on the four tests) is greater or equal to 6, otherwise the exam is failed. This is as far as I got... (The first column is the ID of the student, columns 2-4 are restults of individual tests)
Scores= [1 7 10 9 9;2 6 8 7 6;3 9 10 10 9;4 4 7 6 5;5 7 8 8 9; 6 8 10 9 10; 7 5 6 7 6; 8 8 9 7 6; 9 7 8 8 5; 10 8 10 8 10]
ScoresMean=Scores; ScoresMean(:,1)=[]; mean(ScoresMean,2) % gives mean scores (per row)
ScoresNoID=Scores; ScoresNoID(:,1)=[]; if ScoresNoID(1,:)>6 disp('pass') elseif ScoresNoID(1,:)<6 disp('fail') if ScoresNoID(1,:)<6 = mean(ScoresNoID,2)>6 % this might be wrong... disp('resit')
as you can see, I am already stuck at the beginning. I would appreciate any help!

Accepted Answer

dpb
dpb on 24 Apr 2014
Edited: dpb on 24 Apr 2014
Need to read up on logicals in Matlab...I'll post a possible solution and leave it to you to tell me how and why it works and display the results in pretty format...
pass=all(Scores(:,2:end)>=6,2);
resit=mean(Scores(:,2:end),2)>=6 & ~pass;
fail=~pass&~resit;
  3 Comments
dpb
dpb on 24 Apr 2014
Edited: Image Analyst on 24 Apr 2014
Since this is clearly homework, I'll just throw that back to you --
doc all % explains all :)
And, now figure out how you're going to explain to your instructor how you came up with this solution... :)
Oh, and for submittal I'd expect a useful display of results identifying each student with their result. How you might go about that and what is the real interpretation programmatically of the result you have at the moment?
Image Analyst
Image Analyst on 24 Apr 2014
Evidently he totally ignored by link above about how to format code.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!