Identify Program Dependencies
If you need to know what other functions and scripts your program is dependent upon, use one of the techniques described below.
Simple Display of Program File Dependencies
For a simple display of all program files referenced by a particular function, follow these steps:
functionsto clear all functions from memory (see Note below).
Execute the function you want to check. Note that the function arguments you choose to use in this step are important, because you can get different results when calling the same function with different arguments.
inmemto display all program files that were used when the function ran. If you want to see what MEX-files were used as well, specify an additional output:
[mfiles, mexfiles] = inmem
Detailed Display of Program File Dependencies
For a more detailed display of dependent function information, use the
matlab.codetools.requiredFilesAndProducts function. In addition to
which MathWorks® products a particular function depends on. If you have a function,
myFun, that calls to the
edge function in
the Image Processing Toolbox™:
[fList,pList] = matlab.codetools.requiredFilesAndProducts('myFun.m'); fList
fList = 'C:\work\myFun.m'
The only required program file, is the function file itself,
ans = 'MATLAB' 'Image Processing Toolbox'
myFun.m, requires both MATLAB® and the Image Processing Toolbox.
Dependencies Within a Folder
The Dependency Report shows dependencies among MATLAB code files in a folder. Use this report to determine:
Which files in the folder are required by other files in the folder
If any files in the current folder will fail if you delete a file
If any called files are missing from the current folder
The report does not list:
Files in the
toolbox/matlabfolder because every MATLAB user has those files.
Therefore, if you use a function file that shadows a built-in function file, MATLAB excludes both files from the list.
Files called from anonymous functions.
The superclass for a class file.
MATLAB does not resolve these files until run time, and therefore the Dependency Report cannot discover them.
Some method files.
The Dependency Report finds class constructors that you call in a MATLAB file. However, any methods you execute on the resulting object are unknown to the report. These methods can exist in the
classdeffile, as separate method files, or files belonging to superclass or superclasses of a method file.
To provide meaningful results, the Dependency Report requires the following:
The search path when you run the report is the same as when you run the files in the folder. (That is, the current folder is at the top of the search path.)
The files in the folder for which you are running the report do not change the search path or otherwise manipulate it.
The files in the folder do not load variables, or otherwise create name clashes that result in different program elements with the same name.
Do not use the Dependency Report to determine which MATLAB code files someone else needs to run a particular file. Instead
Creating Dependency Reports
Use the Current Folder pane to navigate to the folder containing the files for which you want to produce a Dependency Report.
On the Current Folder pane, click , and then select Reports > Dependency Report.
The Dependency Report opens in the MATLAB Web Browser.
If you want, select one or more options within the report, as follows:
To see a list of all MATLAB code files (children) called by each file in the folder (parent), select Show child functions.
The report indicates where each child function resides, for example, in a specified toolbox. If the report specifies that the location of a child function is unknown, it can be because:
The child function is not on the search path.
The child function is not in the current folder.
The file was moved or deleted.
To list the files that call each MATLAB code file, select Show parent functions.
The report limits the parent (calling) functions to functions in the current folder.
To include local functions in the report, select Show subfunctions. The report lists local functions directly after the main function and highlights them in gray.
Click Run Report on Current Folder.
Reading and Working with Dependency Reports
The following image shows a Dependency Report. It indicates that
chirpy.m calls two files in Signal Processing Toolbox™ and one in Image Processing Toolbox. It also shows that
mobius.m, which is in the current folder.
The Dependency Report includes the following:
MATLAB File List
The list of files in the folder on which you ran the Dependency Report. Click a link in this column to open the file in the Editor.
The function or functions called by the MATLAB file.
Click a link in this column to open the MATLAB file listed in the same row, and go to the first reference to the called function. For instance, suppose your Dependency Report appears as shown in the previous image. Clicking \images\images\erode.m opens
chirpy.mand places the cursor at the first line that references
erode. In other words, it does not open
Multiple class methods
Because the report is a static analysis, it cannot determine run-time data types and, therefore, cannot identify the particular class methods required by a file. If multiple class methods match a referenced method, the Dependency Report inserts a question mark link next to the file name. The question mark appears in the following image.
Click the question mark link to list the class methods with the specified name that MATLAB might use. MATLAB lists almost all the method files on the search path that match the specified method file (in this case,
freqresp.m). Do not be concerned if the list includes methods of classes and MATLAB built-in functions that are unfamiliar to you.
It is not necessary for you to determine which file MATLAB will use. MATLAB determines which method to use depending on the object that the program calls at run time.