Documentation Center

  • Trial Software
  • Product Updates

depfun

List dependencies of function or P-file

depfun will be removed in a future release. Use matlab.codetools.requiredFilesAndProducts instead.

Syntax

  • list = depfun(fun) example
  • [list,builtins] = depfun(fun)
  • [list,builtins,classes] = depfun(fun)
  • [list,builtins,classes,prob_files] = depfun(fun)
  • [list,builtins,classes,prob_files,~,eval_strings] = depfun(fun)
  • [list,builtins,classes,prob_files,~,eval_strings,called_from] = depfun(fun) example
  • [list,builtins,classes,prob_files,~,eval_strings,called_from,opaque_classes] = depfun(fun)
  • ___ = depfun(fun1,...,funN)
  • ___ = depfun(___,option1,...,optionM) example

Description

example

list = depfun(fun) returns the paths of MATLAB® program files that fun requires to run, where fun is a function, a P-file, or a figure file for a user interface. The output list includes second-level functions that fun calls directly, functions that the second-level functions call, and so on. The depfun function also displays a report in the Command Window.

    Note:  

    • depfun does not always list all dependent files. For example, depfun does not list files hidden in callbacks or files whose names are constructed dynamically for evaluation.

    • The output list often includes extra files that are not called when the function is actually evaluated.

    • If depfun returns a parse error for any of the required functions, then the rest of the output of depfun might be incomplete. Correct the problematic files and invoke depfun again.

[list,builtins] = depfun(fun) returns the built-in functions that fun requires.

[list,builtins,classes] = depfun(fun) returns the MATLAB classes that fun requires.

[list,builtins,classes,prob_files] = depfun(fun) returns the files that depfun cannot parse, find, or access. If there are problematic files (that is, if prob_files is not empty), then the rest of the output of depfun might be incomplete. Correct the problematic files, and then invoke depfun again.

[list,builtins,classes,prob_files,~,eval_strings] = depfun(fun) returns a list of files that contain calls to eval or related functions (evalin, feval, or evalc). These calls potentially use functions that are not in list.

The fifth output argument for depfun is not implemented, and returns an empty structure array. To request arguments later in the list, use the tilde symbol (~) as a placeholder. The tilde suppresses the creation of an extra, empty variable.

example

[list,builtins,classes,prob_files,~,eval_strings,called_from] = depfun(fun) returns a cell array of indices that maps each function in list to the set of functions that call it. That is, list{called_from{k}} returns the paths to the functions that call the function in list{k}.

[list,builtins,classes,prob_files,~,eval_strings,called_from,opaque_classes] = depfun(fun) returns the opaque classes that fun requires, such as Java® or COM classes.

___ = depfun(fun1,...,funN) returns the functions required for multiple functions fun1,...,funN. You can request any of the outputs from the previous syntaxes.

example

___ = depfun(___,option1,...,optionM) modifies the output as described by the specified options. For example, specify '-toponly' to list only the functions that fun calls directly. You can precede the options with one or more function names.

Examples

expand all

Identify Required Functions

Identify the MATLAB program files that strtok.m requires to run.

fun = 'strtok.m';
list = depfun(fun);

MATLAB displays a summary report in the Command Window and stores the list of files in variable list.

Identify Top-Level Dependencies Only

List only the program files that strtok.m calls directly.

fun = 'strtok.m';
list = depfun(fun,'-toponly')
==========================================================
depfun report summary:(top only)
----------------------------------------------------------
-> trace list:           2 files  (total)
                         1 files  (total arguments)
                         0 files  (arguments off MATLABPATH)
                         0 files  (argument duplicates on MATLABPATH)
----------------------------------------------------------
Notes: 1. Use argument  '-quiet' to not print this summary.
       2. Use arguments '-print','file' to produce a full
          report in file.
       3. Use argument  '-all' to display all possible
          left hand side arguments in the report(s).
==========================================================

list = 

    'matlabroot\toolbox\matlab\strfun\strtok.m'
    'matlabroot\toolbox\matlab\strfun\@cell\strtok.m'

Determine Which File Invokes Each Function

One of the functions that strtok.m depends upon is num2cell. Determine which file in the dependency list calls num2cell.

Identify the functions that strtok.m requires (list) and the files that invoke each of those functions (called_from).

fun = 'strtok.m';
[list,builtins,classes,prob_files,~,eval_strings,...
    called_from] = depfun(fun);

Find the index for num2cell within the dependency list.

num2cell_path = which('num2cell');
num2cell_index = find(ismember(list,num2cell_path))
num2cell_index =
     5

Identify the file that calls num2cell.

calls_num2cell = list{called_from{num2cell_index}}
calls_num2cell =
     matlabroot\toolbox\matlab\elmat\repmat.m

Input Arguments

expand all

fun — Function namestring | cell array of strings

Function name, specified as a string or a cell array of strings.

fun must be on the MATLAB path, as determined by the which function. If the path contains any relative folders, then files in those folders also will have a relative path in the output.

Example: 'plot.m'

Example: 'plot.m','mesh.m'

Example: {'plot.m','mesh.m'}

Data Types: char | cell

option — Reporting option'-toponly' | '-verbose' | '-quiet' | '-print' | ...

Reporting option, specified as one of the following strings.

Option

Description

'-toponly'

Identify only the files used directly by the specified function(s), fun.

'-verbose'

Display additional internal messages.

'-quiet'

Display only error and warning messages, and not a summary report.

'-print',filename

Print a full report to the specified file.

'-all'

Display all outputs in the report, but return only the specified output arguments.

'-expand'

Include both indices and full paths in an exported report for the call or called_from list. Requires the '-print' option. This information does not appear in the Command Window report.

'-calltree'

Replaces the called_from list with a list of functions that each file calls, as derived from the called_from list.

Example: '-print','myreport.txt'

Data Types: char

Output Arguments

expand all

list — Paths to required filescell array of strings

Paths to required files, returned as a cell array of strings.

builtins — Required MATLAB built-in functionscell array of strings

Required MATLAB built-in functions, returned as a cell array of strings.

classes — Required MATLAB classescell array of strings

Required MATLAB classes, returned as a cell array of strings.

prob_files — Files that depfun cannot parse or accessstructure

Files that depfun cannot parse or access, returned as a structure with these fields:

  • name — Path to the file

  • listindex — Index of the file in list

  • errmsg — Error message that describes the problem

  • errid — Error identifier, if present

eval_strings — Files that call evaluation functionscell array of strings

Files that call evaluation functions, returned as a cell array of strings.

called_from — Indices to files that call each function in listcell array

Indices to files that call each function in list, returned as a cell array. Each element of the cell array is a numeric array of indices that correspond to elements in list. The list and called_from outputs have the same length.

opaque_classes — Paths to opaque classescell array of strings

Paths to opaque classes, such as Java or COM classes, returned as a cell array of strings.

Was this topic helpful?