automatic code evaluation for a live script
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
BLP
am 4 Mai 2023
Bearbeitet: Cris LaPierre
am 6 Jul. 2023
Hallo everybody,
I am trying to write a code for automatic evaluation of student code. I know that I can use MATLAB Grader but ... I decided, that it would be better if the students work in the MATLAB environment and that their prepare reports using preformatted live scripts. I would like to give to students p-code files, which they can run and check if their solution are correct or not and correct it when necessary. The simplest idea came to me was to run the student live script and compare values of selected variables or object properties with reference variables, but in such a case students will gest error messages for the task they have not solved yet. However, I could not find any method to programmatically run only selected section of a live script. Trying to give the possibility to evaluate section by section I ended up with an idea of a function which will accept two input arguments: mlx file name and section number and which will be executed using a Button control element:
- create temporary directory for temporary m files
- convert the mlx file to a temporary m file (matlab.internal.liveeditor.openAndConvert(mlxFileName,mFileName);)
- read m file as a string array (readlines)
- find in the string array lines with task markers (strfind)
- save the part of the code for a selected task (from the string array) in a temporary m file
- run test for the temporary m-file (for the selected task only) and give evaluation results
I have implemented part of the algorithm to the point 5, including this point. It works but it seems to be a bit time consuming. I am wandering whether there is a better way, without saving the temporary m files, but I do not have other ideas how to extract the code from a certain section of a live script and how to run it, programmatically.
I would appreciate any help.
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 4 Mai 2023
This may be overly simplistic, but based on what you have said, i would look into using Try-Catch statements. So I would try to grade a variable, but if it doesn't yet exist, the error will cause the code to switch to the Catch statement, where I can return a message about the variable not existing yet, but still continue running my assessment function.
Weitere Antworten (1)
BLP
am 8 Mai 2023
3 Kommentare
Cris LaPierre
am 8 Mai 2023
Bearbeitet: Cris LaPierre
am 8 Mai 2023
You can read about these 3 functions here:
assessFunctionPresence will return an error if the student solution does NOT use the listed function(s).
assessFunctionAbsence will return an error if the student solution DOES use the listed function(s).
So design your script to use the function that would not return an error when students do what you expect.
These functions check files, not sectinos of code, so if you want to use them, you are back to a workflow of turning each section of code into its own file.
One thing to be aware of - these functions do not check context/useage, just presence/absence.
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!