In MATLAB Grader, how can I capture the printed output of a script type problem?
Show older comments
My understanding is that the expected way to capture the printed output of code is using evalc. I understand how I would do this for a function-type problem, but is there a name I can pass into evalc to call a learner's script for a script-type problem?
An example problem:
(a) Create a variable x=5
(b) Create a variable y=2*x, and display its value using the disp function. This should be the only output printed by your code.
I would like to be able to mark as incorrect submissions such as
x = 5
y = 2*x
disp(y)
to force students to learn how to use semicolons, etc.
I was envisioning something along the lines of
learner_output = evalc('learnerScript');
assert(strcmp(learner_output, reference_output))
3 Comments
Dyuman Joshi
on 30 Mar 2024
"to force students to learn how to use semicolons, etc."
If the goal is to check for something that should be present or absent in the code, you could read the file as text - fileread and check if the lines end with a semi-colon.
This is frequently used in Cody test suites when restricting certain commands, here is a problem you can check out - https://in.mathworks.com/matlabcentral/cody/problems/59621-beam-me-up-scotty
Benjamin Walker
on 30 Mar 2024
Dyuman Joshi
on 30 Mar 2024
Ah, I see.
In that case, using evalc seems to be the sole option.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!