I'm working on some MATLAB coding assignments for students and am using MATLAB Grader to provide assessment and feedback. I would like to have students write functions. This is to achieve two objectives, one to further their understanding of concepts from the course and so that when they are done, they can use their function (that they know and understand) to solve other homework problems, use it in labs, homeworks and exams for computing values, etc.. Much like they might do in industry.
Since within Grader one can't assess intermediate variables within the student's functions I was looking for a way to better help them debug their code. To do this I added a variable to the return variables that is a structure. I called it debug. Then for my assessments I assigned fields to intermediate values that I can check in the assessment to provide feedback to the students if these values are wrong.
For example a snippet of a learner template for a function to perform the inverse DFT is shown below. The reference template would be similar and pass back the variables that I think would be useful to assess and provide feedback on if not correct.
function [xOut, debug] = IDFT( ReX, ImX )
debug.variable1 = variable1;
debug.variable2 = variable2;
debug.learnerVar1 = learnerVar1;
debug.learnerVar2 = learnerVar2;
The assessment can compare the learner values to the reference values. However I had to do the comparison using the assert function as the assessVariableEqual function wouldn't accept the structure and field format for the first variable (in quotations) (e.g. assessVariableEqual('debug.variable1' , debug_ref.variable1) does not work)
For example:
[xOut, debug] = IDFT(ReX, ImX);
[xOut_ref, debug_ref] = reference.IDFT( ReX, ImX )
assert( debug.variable1 == debug_ref.variable1, 'The scaled real values of the IDFT input are incorrect. Check your code starting there' );
This works, but seems complicated. I was wondering if anyone else has solved this in a different way? Any feedback would be great!
Thanks,
Mark