The current (R2020a) way to achieve this in MATLAB Grader is to use a MATLAB Code assessment type and logical statements to perform the checks sequentially.
As an example, consider a problem where students are to take an input vector vec and, using a for loop, create an array mat where each row contains the vector raised to the row number.
Common errors:
- Not capturing the result of each loop
- Reversing the assignment indices
In order to check these 2 common errors specifically, plus any other solution students may submit, my assessment code might be:
assert(exist('mat',"var")==1,'Your solution must be assigned to a variable named ''mat''');
if size(mat,1) == 1
assert(false,'Your solution must capture the results of each loop in a row of ''mat''');
elseif size(mat,1) == 4
assert(false,'Your assignment indices may be reversed');
else
assessVariableEqual('mat',referenceVariables.mat)
end
Note that the custom feedback inside an assert statement will appear in red text.
Best Answer