MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

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) In the Project tab, click Custom Tasks and then select Manage Custom Tasks.
The Manage Custom Tasks dialog box opens.
2 Click Add and then select Add Using New Script. If you want to add an existing
script as a custom task, select Add Using Existing Script
(^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 the checkcode function.
[~,~,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:
Create Custom Tasks

Free download pdf