Main Content

Create Assessment Items in MATLAB Grader

MATLAB® Grader™ is a browser-based environment for creating interactive MATLAB assessment items that you can include in a course. For each assessment item, you describe the coding task, provide a reference solution, and specify how to assess the learner solution. MATLAB Grader automatically runs assessment tests to determine the correctness of a solution and provide feedback..

To access MATLAB Grader, log in to your MathWorks® account at grader.mathworks.com.

Set Up a Collection

Start by creating a collection to store and organize your assessment items. In MATLAB Grader, on the Content tab, click Create Collection. MATLAB Grader prompts you to create a name for the collection and for a group within the collection to store your assessment items. You can change the name of a collection or group at any time.

Add and Describe the Assessment Item

Add an assessment item to your collection by clicking Add Item, which takes you to the Add Item page. From this page, you can create a new assessment item, select an existing assessment item from one of your collections, or select a sample assessment item from the "Getting Started with MATLAB Grader" collection. This collection includes sample assessment items that you can use as a starting point.

On the Assessment Item page, specify a title, description, and instructions for the assessment item as you want them to appear for your learners. The description and instructions can include formatted text, images, links, and equations. In your instructions, specify the inputs the learner must use in their code and the outputs the code must generate. Include specific details in the instructions that impact assessment, such as the expected data types and units of measurement. In this example, the instructions specify that learners should calculate the volume of a cone in mm3 and assign the result to a variable named vol.

Sample assessment item description and instructions include an equation and a bulleted list.

If your assessment item requires the use of data or code files, attach them. Under Files Referenced, click Add File.

Define the Solution

MATLAB evaluates scripts and functions differently, so you must specify which type of code your learners should create for each assessment item. When assessing scripts, you can check the values of all variables. When assessing functions, you can check only the function output values.

For either assessment item type, write a reference solution that MATLAB Grader can use to assess the learner solution. Learners cannot view the reference solution. In this example from a script assessment item, the reference solution calculates the volume of a cone and assigns the value to variable vol.

Sample reference solution shows three lines of code: r=5; h=12; and vol=(h*pi*r^2)/3;.

Optionally, provide a template with starter code for the learner. You can lock lines of code that the learner cannot edit by clicking the lock icon. In this example of a learner template, a comment line and the lines of code that set the cone parameters are locked.

Sample learner template shows locked lines.

When you create a function assessment item, consider locking the function definition line in the learner template. Locking this line ensures that your assessment tests can call the learner solution with the expected name, such as tempF2C in this example.

Sample learner template with the function definition line locked. The definition is function tempC = tempF2C(tempF).

In function assessment items, you can also provide code for learners to call their functions. This code can include representative inputs and outputs. Learners can run this code as provided or modify it for their own testing. Learners can also revert modified code to your version of the code, if needed. This code runs when learners click Run Function, but it does not run when learners click Submit. In this example, assign a temperature to variable tF and pass it to the learner function.

A code box titled "How to call the function (when the learner clicks 'Run')" shows two lines of code: tF = 212; and tC = tempF2C(tF).

To view and interact with an assessment item as the learner will view it, click Learner Preview at the bottom of the Assessment Item page. Learners can open assessment items in MATLAB Online™, but on the Preview page, this option is only available after you save the assessment item as final.

Assess Learner Solutions

MATLAB Grader includes predefined test types to check the value of a variable and to check whether the learner uses or avoids a specified function or keyword.

For example, to assess the value of a variable in a script assessment item, follow these steps:

  1. In Test, click Add Test.

  2. In the text box at the top of the test details, enter a short description. The learner can view this description while coding their solutions. The description sets expectations about the assessment test.

  3. Under Test Type, select Variable Equals Reference Solution. Specify the name of the variable you want to compare.

  4. Optionally, add feedback that you want to appear for incorrect results in addition to the default feedback. To view the default feedback, click the information icon for this box. Feedback can include formatted text, images, equations, and links.

A sample test with Test Type set to Variable Equals Reference Solution. The text box at the top contains the text "Is the calculated volume correct?" and the text box for optional feedback contains the text "Check that the equation is using the provided values for r and h."

You can also write MATLAB code to check solutions. This code can use functions that correspond to the predefined test types: assessVariableEqual, assessFunctionPresence, and assessFunctionAbsence. Alternatively, you can write a custom test that returns an error for incorrect results.

Within your code:

  • For script assessment items — To refer to variables in your reference solution, add the prefix referenceVariables, such as referenceVariables.myvar. To refer to learner variables, use the variable name.

  • For function assessment items — To call the function in your reference solution, add the prefix reference, such as reference.myfunction. To call the learner function, use the function name. You cannot assess variables within functions.

For example, check that a learner’s tempF2C function correctly converts temperatures from Fahrenheit to Celsius. First, call the learner function and the reference function with the same input. Then, call assessVariableEqual to compare the results.

A MATLAB code test shows four code lines: tempF = 78; tempC = tempF2C(tempF); expected_temp = reference.tempF2C(tempF); assessVariableEqual('tempC',expected_temp);.

Assessment tests can include these additional options:

  • Scoring method — By default, a solution is correct if all tests run without errors and incorrect if any tests generate an error. To allow partial credit, set the method to Weighted. Then, specify the relative weight for each assessment test.

  • Only show feedback for initial error (for script assessment items only) — Selecting this option displays the complete message for the first error and collapses information for subsequent errors. Learners have an option to display all subsequent feedback.

  • Pretest — When this option is selected, learners can run a pretest before they submit their final solution. Learners can view the code for a pretest, so make sure that the code does not include a solution to the assessment item.

Verify that your reference solution runs and passes the assessment tests by clicking Validate Reference Solution at the bottom of the page.

For more information about writing assessment tests, see Test Solutions from Learners.

Save the Assessment Item

Assessment items have two possible states: draft and final. Learners can only view assessment items that are in a final state. You can change the state of an assessment item at any time by clicking Save as Final or Set to Draft.

See Also

| |

Related Topics

Go to top of page