MATLAB: MATLAB Grader marks the submission as incorrect if it contains statements like “clc” and “clear all”

"referencevariables"clearerrorgraderMATLABundefinedvariable

In MATLAB Grader, some assessment tests are being marked incorrect even when I have confirmed that the submitted solution is correct.
I noticed that my submission contains commands like "clc" and "clear". Do they have to do anything with submission.

Best Answer

This is expected behavior. The reason for that is because "clear" removes all the variables created in the reference solution. These variables are often used to compare against variables created in the learner solution. This results in the Variable Equals Reference Solution test type, and any assessVariableEqual tests comparing to a referenceVariable field, to be marked incorrect.
As a possible workaround, the instructors can include the following command when creating questions.
assessFunctionAbsence('clear', 'Feedback', 'Do not use clear in your solution');
Please refer to following documentation page for details about "assessFunctionAbsence" function.