assessFunctionPresence use in Matlab Grader for checking one out of n functions are present

1 view (last 30 days)
I am setting up a test in Matlab Grader to check that students use a for or a while loop in an exercise. They can only use one out of the two. The problem is that there is no way to set up an assessFunctionPresence test for this purpose. Is there any way around it?

Accepted Answer

Cris LaPierre
Cris LaPierre on 29 Oct 2018
The MATLAB Code assessment type allows you to use any code you want to create an assessment. There are ways to achieve the result you want with assessFunctionPresence combined with assessFunctionAbsence, since it is the combination that is important. For example
assert(false,'You must use either a for loop or a while loop, but not both')
Any time a test evaluates false, you are bumped to the next level of the try/catch. If the solution contains both for and while loops, the assert statement will mark the answer false and give the student meaningful feedback on how to correct the code.

More Answers (0)


More Answers in the  Distance Learning Community

Community Treasure Hunt

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

Start Hunting!

Translated by