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!

 Akzeptierte Antwort

dpb
dpb am 24 Apr. 2014
Bearbeitet: dpb am 24 Apr. 2014

0 Stimmen

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 Kommentare

Marcel
Marcel am 24 Apr. 2014
Thanks for the answer! I looked the logicals up and understand what you did there! I came up with the following, according to your answer:
Scores2=Scores
Scores2(:,1)=[]
pass=all(Scores2>=6,2)
resit=mean(Scores2>=6,2) & ~pass
fail=~pass&~resit
the only thing I don't understand is the last "2" in pass=all(Scores2>=6,2).
dpb
dpb am 24 Apr. 2014
Bearbeitet: Image Analyst am 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 am 24 Apr. 2014
Evidently he totally ignored by link above about how to format code.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Apr. 2014

Kommentiert:

am 24 Apr. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by