Include p code in a matlab grader assignment

10 views (last 30 days)
I am an instructor and I am planning to use matlab grader in my course next semester. I would like to add obscured code to some of the assigments. For example, in one of the assigments, the students need to model a set of data as a power law y=a*x^m, where the goal is to find the coefficients a and m. The data is created by a function
function [x,y]=powerLaw()
x=logspace(-2,2,20);
y=3*x.^(-2).*abs((1+(rand(1,20)-.5)/.2));
end
Obviously, I do not want the students to have access to contents of the function. So I would like to include it as a p code. How can I do that?

Accepted Answer

Cris LaPierre
Cris LaPierre on 8 Dec 2022
P-code the function on your computer, then attach the p-code file to your problem. This places the file in the current folder of both the reference and learner solutions. This means any code written in Grader can access this function by calling it by name (powerLaw).
If your students are writing a script, then you could add a call to your function at the top of both the reference and leader scripts to generate the data. I would recommend locking this line in the learner template.
If your students are writing a function, then you can call this function in the "Code to call your function" template, as well as in the assessment tests as appropriate.
For an example of having students use an instructor-provided function in their answer, take a look at the "Boston Temperatures: Getting warmer or not as cold?" example problem in the Getting Started with MATLAB Grader problem catalog. You can access this from the Add Problem screen.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!