Main Content

Create Custom Tasks

Custom tasks are MATLAB®functions that allow you to perform a series of operations on one or more files. You can create a custom task function and then run the custom task on a select set of files in your project. For example, you can create a custom task to check all the code files for errors or to run all the tests in the project.

Create a Custom Task Function

To create a custom task function:

  1. On theProjecttab, click the down arrow to expand theToolsgallery. UnderProject Checks, clickCustom Tasks. In the Custom Task dialog box, clickManage.

  2. ClickAddand then selectAdd Using New Function. If you want to add an existing script as a custom task, selectAdd Using Existing Function.

  3. Specify a file name for the script and save the new file on the MATLAB path. The MATLAB Editor opens the new file containing an example custom task function.

  4. Edit the function to perform the desired action on each file. Use the instructions at the top of the file to guide you to create a custom task with the correct function signature. Your custom tasks must accept a full path to a file as the single input argument and return a single output argument.

    For example, this custom task function extracts Code Analyzer information for each file using thecheckcodefunction.

    [~,~,ext] = fileparts(file); switch ext case {'.m', '.mlx', '.mlapp'} result = checkcode(file, '-string'); otherwise result = []; end

  5. Save the file.

You can use the MATLAB editor to set breakpoints and debug a custom task function, just as with any other MATLAB function.

Run a Custom Task

To run a custom task on a select set of files in your project:

  1. On theProjecttab, click the down arrow to expand theToolsgallery. UnderProject Checks, clickCustom Tasks.

  2. In theIncludecolumn of the table, select which project files you want to run the custom task on.

    To include or exclude multiple files in the table at once, press theShiftorCtrlkey, select the files, and then right-click and selectIncludeorExclude. If the custom task function can identify the files to operate on, include all files.

  3. In theCustom taskfield, select from the available custom task functions. You also can enter the name of a task directly in the field, or clickBrowse.

  4. ClickRun Task运行的任务。自定义任务报告窗口说plays the results.

  5. Examine theResultscolumn in the table to ensure that the custom task ran correctly on all files. To view detailed result information for a file, select the file in the table. The results pane at the bottom of the Custom Task Report displays the details.

保存自定义任务报告

Saving a Custom Task Report is useful if you want to save a record of the custom task results, or if you want to share the results with others.

To save the Custom Task Report, click thePublish Reportbutton at the bottom of the Custom Task Report. You can either save the report as an HTML file or aMicrosoft®file. If you haveMATLAB Report Generator™, you also can save the report as a PDF file.

To see the report file and add it to your project, switch to theAllfiles view.

Related Topics