Main Content

Create MATLAB Exercise Using MATLAB Course Designer

This example shows how to add a MATLAB® exercise to a course in MATLAB Course Designer™.

MATLAB Exercise titled "Compute Sine of Multiples of Pi". The task background reads "To compute sin(X*pi) accurately, without using pi as a floating-point approximation of pi, you can use the sinpi function. For example, sinpi(n) is exactly zero for integers n and sinpi(m/2) is +1 or -1 for odd integers m". The Task reads "Compute the sine of pi accurately. Do not use the 'sin' function." On the right side of the screen there is a MATLAB editor for the learner to add their solution.

MATLAB exercises allow learners to receive automated assessments and feedback after submitting their task solutions. For examples of MATLAB exercises, see courses like MATLAB Onramp.

For more information on MATLAB Course Designer, see Create Courses Using MATLAB Course Designer.

Create Course

Open MATLAB and Simulink® Online™ Courses from your learning management system (LMS) or at course-designer.mathworks.com. For information on how to integrate MATLAB and Simulink Online Courses into your LMS, see Integrate MATLAB and Simulink Online Courses with Learning Management System (LMS).

To open MATLAB Course Designer from your LMS, click Launch Course Designer.

Create a new course by clicking Create Course. Choose a course title.

Create course dialog box with a blank title field.

Create Exercise

To add a MATLAB exercise, follow these steps.

  1. Add a course module by clicking Add Module.

  2. Expand the module pane.

  3. Add a MATLAB exercise to the module by clicking Add Learning Activity > MATLAB Exercise.

  4. Edit the exercise by clicking Edit next to the untitled MATLAB exercise.

An Untitled MATLAB Exercise inside a course module name "Module 1."

Add Title

The exercise title sets learner expectations for the exercise. A good exercise title defines the scope of the learning activity, particularly in the context of the module title and the other learning activities in the module.

To add a title, click Title in the left navigation pane of the Edit Exercise window. The Title pane opens. Enter the title of your exercise in the Exercise Title text box.

Title pane of the Edit Exercise window. The text in the Exercise Title box says "Compute sine of multiples of pi."

Add Background

The task background sets the context for the task learners must perform to complete the exercise. Use the task background to explain the learning objective and provide high-level information that learners need to know to be able to complete the task.

Click Background in the left navigation pane. The Background pane opens. Enter the task background into the text box.

Background pane of the Edit Exercise window. The text in the text box describes the "sinpi" function.

Add Task Description

The task description provides instructions for the learner to follow to complete the task. Provide specific instructions, such as which functions to use and which variable names to use.

Click Task in the left navigation. The Task pane opens. Enter the task description in the text box.

Screenshot showing the Task pane of the Edit Exercise window. The text in the text box says "Compute the sine of pi accurately. Do not use the "sin" function.".

To preview the title, background text, and task in the task panel, click Refresh Preview.

Add Starting Code

Click Starting Code and Solution in the left navigation pane.

The starting code is an MLX (*.mlx) file containing the code snippet that learners see when they open the exercise.

The exercise starts with a blank starting code file or upload an MLX (*.mlx) file by clicking Upload. To edit the file, close the Edit Exercise window and add content to the starting code file startingCode.mlx.

The learner template file. The title of the script is "Compute Sine of Multiples of Pi" and the code is "x =".

Save the file. To reopen the Edit Exercise window, click Edit Exercise in the task pane on the left.

Add Solution

Click Starting Code and Solution in the left navigation pane.

The solution is an MLX (*.mlx) file containing the solution to the task. You can use the solution to assess the learner solution by adding tests. You can also allow learners to access the solution by selecting Enable learner to see solution in the left navigation pane.

The exercise starts with a blank solution file or upload an MLX (*.mlx) file by clicking Upload. To edit the file, close the Edit Exercise window and add content to the solution file solution.mlx.

The solution file. The code in the script is "x = sinpi(1);".

Save the file. To reopen the Edit Exercise window, click Edit Exercise in the task pane on the left.

Add Supporting Files

Click Supporting Files in the left navigation pane. To add a supporting file, click Upload. Both the learner solution and the reference solution can access the supporting files.

These file formats are not supported:

  • EXE (*.exe)

  • SH (*.sh)

  • JS (*.js)

Add Assessments

You can use assessments to check if the learner solution produces correct results. You can also check if the learner solution includes or excludes specific keywords or functions.

Click Assessments in the left navigation pane.

To add assessments, you must have a reference solution. Click Run Solution to generate the workspace variables that the tests can access. You can rerun the solution to regenerate the workspace variables at any time.

First, add a test that checks if the learner solution uses the sin function. From the Test list, select Is Function/Keyword Absent? and click Add. Enter sin in the Is Function/Keyword Absent? text box.

Next, add a test that checks if the value of x is correct. From the Test list, select Is Variable Correct? and click Add. From the Is Variable Correct? list, select x.

The sinpi function returns integers for integer input. Expand the Tolerance pane and set the relative and absolute tolerances to zero. The tolerance the software uses is:

|xlearner-xsolution| ≤ max( (absolute tolerance), (relative tolerance) × max(xlearner,xsolution) ),

where xlearner is a variable created by the learner solution and xsolution is the same variable created by the solution.

Assessments pane of the Edit Exercise window, showing both a test checking for the absence of sin, and a test checking the accuracy of x. The relative and absolute tolerances of the correctness test are set to zero

For more information about tests in MATLAB Course Designer, see MATLAB Exercise Assessment Tests in MATLAB Course Designer.

Add Hint

You can provide a hint to help the learner complete the task. A good hint can provide additional reference information, address common mistakes, and remind learners of important details such as functions to use.

When a learner works on a task, the hint for that task is hidden until they click the Hint hyperlink.

Click Hint in the left navigation. The Hint pane opens. Enter the hint in the text box.

The Hint pane of the Edit Exercise window. The text in the text box says "Use the "sinpi" function".

Preview Exercise

To preview what the exercise looks like from the perspective of the learner, close the Edit Exercise window and click Learner Preview.

A preview of the learner's view of the exercise. It includes the task background and task description on a panel on the left and the starting code template in a MATLAB editor on the right.

Next Steps

To return to the Edit Exercise window, click Return to Editing. To return to your course, click Return to Course.

You can add additional modules and learning activities to your course. When your course is ready, click Publish. You can then assign your course to learners from your LMS. For more information on how to assign courses, see Add MATLAB and Simulink Online Courses to LMS Course.

See Also

Topics