Matlab Grader file solution.m contains learner solution in one exercise, reference solution in another exercise
5 views (last 30 days)
Show older comments
Dennis Mueller
on 2 Jul 2021
Commented: Dennis Mueller
on 5 Jul 2021
Hello,
Short version of my question : Why do i get the reference solution from fileread('solution.m') in one exercise and the learner solution in another exercise? Both problems are script based problems where the learner template is a copy of the reference solution with some gaps the students have to fill.
Detailed information (if you have the time to read it):
i am trying to create an exercise similar to the one described in this link: MATLAB Grader. How to check vectroization in students solution? - MATLAB Answers - MATLAB Central (mathworks.com). There are two for-loops in my learner template and the inner for-loop should be replaced by a vectorization.
To check if the student performed the vectorization, the test should check how often the keyword "for" is used. However, when i use SolutionFile = fileread('solution.m') the reference solution is saved in SolutionFile and not the learner solution. In another exercise, this works totally fine with the keyword 'plot' (i get the learner solution with fileread('solution.m') in the other exercise). I tried to implement the test for vectorization into a MATLAB Grader Assessment and into a MATLAB-function, which is provided to the exercise in a referenced file. This is my code to check vectorization
SolutionFile = fileread('solution.m')
MaxNumber = 1;
NumberOfforOperators = numel(strfind(SolutionFile,'for'))
if NumberOfforOperators>MaxNumber
error('You used for to often, it seems you did not vectorized your code properly')
end
And these are all the files in the Grader exercise when i call ls() (at the end of the reference solution and clicking on "validate reference solution"):
'+reference ScoringEngineSharedVariable1.m ScoringEngineTestPoint1.p ScoringEngineTestPoint2.p solution.m solutionTest.m testvectorization.m '
With testvectorization.m my MATLAB-function with the code i posted above. If i try to access +reference i receive an error message, solution.m contains the reference solution. The learner solution is not contained in any of the files.
My function counts a total number of 7 "for"s in the reference solution, all the "for"s in the comments are also counted.
Note: When i call my function inside the learner preview, it contains the code of the learner preview. In this way i could create the exercise but still i wonder why solution.m can contain the learner solution or the reference solution?
(In one exercise i get the learner solution only by calling my function which is in a referenced file in the learner template/preview, in the other exercise i can access the learner solution in the same way or in an assessment)
0 Comments
Accepted Answer
Cris LaPierre
on 2 Jul 2021
Am I correct in assuming the issue is ocurring when you click 'Validate Reference Solution'?
Perhaps a brief explanation of what Grader is doing with a script-type problem will be helfpul. At its core, MATLAB Grader compares a variable from the reference solution to a variable in the learner solution. To achieve this, when a user clicks Submit, first the reference solution is run. All the variables created are added to the referenceVariables structure. Then the workspace is cleared and the learner solution is run. Finally the assessment tests are run.
Because the learner template could be anything, when you validate, the reference solution is run twice - first as the reference solution, then again as the learner solution. So when validating, the reference solution is also the solution file.
Validate Reference Solution is therefore a means for ensuring your reference solution does not contain syntax or runtime errors, and that your reference solution can pass your assessment tests. The learner solution is not run or checked when validating.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!