automatic code evaluation for a live script
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
BLP
el 4 de Mayo de 2023
Editada: Cris LaPierre
el 6 de Jul. de 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 comentarios
Respuesta aceptada
Cris LaPierre
el 4 de Mayo de 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.
Más respuestas (1)
BLP
el 8 de Mayo de 2023
3 comentarios
Cris LaPierre
el 8 de Mayo de 2023
Editada: Cris LaPierre
el 8 de Mayo de 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.
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!