- First determine if the student variable exists.
- Next, determine if the student variable is the same data type as the reference variable.
- Then determine if the student variable is the same size as the reference variable.
- Finally, determine if all the values in the student variable are the same as the values in the reference variable. For numeric values, apply a tolerance.
Is it possible to suppress the default error message of the function assessVariableEqual?
10 views (last 30 days)
Show older comments
Franz Kallage
on 3 Nov 2020
Answered: David Kosfelder
on 25 Nov 2020
For my Matlab Grader Courses I use the build in function assessVariableEqual.
In order to give the students a better hint for the correct solution I define my own error messages with the keyword 'Feedback' in the function.
Sometimes the default error message is confusing for the students and I want to suppress the message, but there seems to be no possibility to do so.
0 Comments
Accepted Answer
Cris LaPierre
on 3 Nov 2020
Edited: Cris LaPierre
on 3 Nov 2020
There is currently no way to suppress the default feedback when using the built-in assessment function assessVariableEqual. The alternative is to instead perform the grading using assert statements. Assert will only show the message you provide (see tips below for more).
To duplicate the behavior of assesVariableEqual, you must
The first 3 tests are necessary to ensure the values can be compared without causing an error.
Here's an example (untested):
% does variable f exist?
assert(exist('f')==true,'The submission must contain a variable named f')
% is f a double?
assert(isa(f,'double'),'Variable f must be of data type double.')
% check size
assert(all(size(f)==size(referenceVariables.f)),'Variable size is incorrect');
% Check values using assert
assert(all(abs(f-referenceVariables.f)<0.0001),'The variable f contains an incorrect value');
1 Comment
Cris LaPierre
on 3 Nov 2020
Edited: Cris LaPierre
on 3 Nov 2020
Here is an example from Grader. Both tests perform the same test. The first test uses assessVariableEqual, so the default feedback is shown. The second test uses asserts, and only displays the custom message I have defined.
Tips:
- If you do not define a message with assert, the default message will be 'Assertion failed.'.
assert(all(abs(Vol-referenceVariables.Vol)<0.0001));
- If you do not want any message in red text, define the message as empty: ''.
assert(all(abs(Vol-referenceVariables.Vol)<0.0001),'');
- When using asserts, you can still provide feedback to students through the 'Feedback on Incorrect' rich text editor. This feedback appears just as you entered it.
More Answers (1)
David Kosfelder
on 25 Nov 2020
From my observation Matlab Grader uses errors to fail a test. assessVariableEqual throws an exception if a variable is not equal. You can use try/catch to filter it out and fail the test manually. The second argument makes the message multi-line.
try
assessVariableEqual('avgX',referenceVariables.avgX);
catch
error("The test has failed.\nYour submission is wrong", "");
end
0 Comments
Communities
More Answers in the Distance Learning Community
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!