Providing better feedback to students when assessing FUNCTION problems in MATLAB Grader
Show older comments
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.
%
% IDFT function
%
% The function definition is locked in the learner template
%
function [xOut, debug] = IDFT( ReX, ImX )
% Create a variable debug that is a structure.
% This line is locked in the learner template
debug = struct;
%
% ... Other code and comments
%
% Save debug return variables for my assessment and checking
% These lines are locked in the learner template
debug.variable1 = variable1; % Save and return for debug and assessment
debug.variable2 = variable2; % Save and return for debug and assessment
% Students can define their own fields to return variables for
% checking in their calling code.
% These lines are written by the learner and not locked
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:
% Call the learner function. Include both xOut and debug if you want to get both
% the output and the debug values passed back to the calling function
[xOut, debug] = IDFT(ReX, ImX); % Call your function. Include the debug output
% Call the reference function. Include the debug output
[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
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown 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!

