Help with conditional statements

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!

 Respuesta aceptada

dpb
dpb el 24 de Abr. de 2014
Editada: dpb el 24 de Abr. de 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 comentarios

Marcel
Marcel el 24 de Abr. de 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 el 24 de Abr. de 2014
Editada: Image Analyst el 24 de Abr. de 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 el 24 de Abr. de 2014
Evidently he totally ignored by link above about how to format code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 23 de Abr. de 2014

Comentada:

el 24 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by