Main Content

matlab.codetools.requiredFilesAndProducts

List dependencies of MATLAB program files

Description

fList = matlab.codetools.requiredFilesAndProducts(files) returns a list of the MATLAB® program files required to run the program files specified by files.

The matlab.codetools.requiredFilesAndProducts function is intended to provide you with information to pass on to consumers of your MATLAB program files.

example

[fList, pList] = matlab.codetools.requiredFilesAndProducts(files) also returns a list of the MathWorks® products possibly required to run the program files specified by files.

If you use the matlab.codetools.requiredFilesAndProducts function on MATLAB code that you received, plist only includes the required toolboxes that are installed on your system. In this case, plist can be incomplete.

example

[fList, pList] = matlab.codetools.requiredFilesAndProducts(___,'toponly') indicates that for a file or product to be included in the output, it must be used directly by at least one file specified in files. The 'toponly' input option is case insensitive.

example

Examples

collapse all

Determine the required files and products for the edge function in the Image Processing Toolbox™.

[fList,pList] = matlab.codetools.requiredFilesAndProducts('edge.m')
fList = 

     {}


pList = 

1x2 struct array with fields:

    Name
    Version
    ProductNumber
    Certain

There are no required MATLAB files, but there are two required products.

List the required products.

{pList.Name}'
ans = 

    'MATLAB'
    'Image Processing Toolbox'

In your current working folder, create a function in the file getRandomNumber.m.

function a = getRandomNumber
    rng shuffle
    a = rand;
end

Now, at the command line, determine the required files and products for getRandomNumber.m.

[fList,pList] = matlab.codetools.requiredFilesAndProducts('getRandomNumber.m')
fList = 

    'C:\work\getRandomNumber.m'


pList = 

             Name: 'MATLAB'
          Version: '8.5'
    ProductNumber: 1
          Certain: 1

The only file required to run the getRandomNumber function is the function file itself. The only required MathWorks product is MATLAB.

In your current working folder, create a function in the file displayNumber.m.

function displayNumber
    a = getRandomNumber;
    disp(['Your number is ' num2str(a)])
end

Now, at the command line, determine the required files and products for displayNumber.m.

[fList,pList] = matlab.codetools.requiredFilesAndProducts('displayNumber.m')
fList = 

    'C:\work\displayNumber.m'    'C:\work\getRandomNumber.m'


pList = 

             Name: 'MATLAB'
          Version: '8.5'
    ProductNumber: 1
          Certain: 1

In addition to the function file itself, the displayNumber function requires the getRandomNumber.m file. The only required MathWorks product is MATLAB.

In your current working folder, create a handle class in the file ExampleHandle.m.

classdef ExampleHandle < handle
    % class content
end

In your current working folder, create a class in the file AnotherExampleHandle.m that inherits from ExampleHandle.

classdef AnotherExampleHandle < ExampleHandle
    % class content
end

In your current working folder, create a function in the file getHandles.m that instantiates AnotherExampleHandle objects.

function [h1,h2] = getHandles()
    h1 = AnotherExampleHandle;
    h2 = AnotherExampleHandle;
end

Now, at the command line, determine the required files for getHandles.m.

[fList,~] = matlab.codetools.requiredFilesAndProducts('getHandles.m');
fList'
ans = 

    'C:\work\AnotherExampleHandle.m'
    'C:\work\ExampleHandle.m'
    'C:\work\getHandles.m'

Determine the required files that are directly required for getHandles.m.

[fList,~] = matlab.codetools.requiredFilesAndProducts('getHandles.m','toponly')
fList = 

    'C:\work\AnotherExampleHandle.m'    'C:\work\getHandles.m'

Although AnotherExampleHandle.m requires ExampleHandle.m, that file is not a direct requirement for getHandles.m.

Input Arguments

collapse all

List of files for analysis, specified as a character vector, a cell array of character vectors, or a string array. Each element is the name of a single MATLAB program file. For example, files is a list of MATLAB program files that you intend to provide to other users. The matlab.codetools.requiredFilesAndProducts function provides you with requirements information to pass along with your files.

To ensure an accurate dependency analysis, files and dependencies must be on the MATLAB path. matlab.codetools.requiredFilesAndProducts does not return information about dependent files not on the path.

Example: 'myFile.m' or "C:\Program Files\MATLAB\R2014a\my_work\myFile.m"

Example: {'myFile.m','myOtherFile.m'}

Example: cellstr(ls('*.m'))

Output Arguments

collapse all

List of user-authored MATLAB program files required by files, returned as a cell array of character vectors. Each character vector indicates the full path of the required file. fList does not include built-in MATLAB files, since these files are installed with the products listed in pList.

fList includes dependent files that are accessed using standard file format and low-level I/O functions. These dependent files include text files, spreadsheets, images, audio, video, and XML files. For example, if you are analyzing a file that contains the code load('mydata.mat'), the matlab.codetools.requiredFilesAndProducts function includes mydata.mat in fList.

Functions that support automatic detection of dependent files include audioinfo, audioread, csvread, daqread, dlmread, fileread, fopen, imfinfo, importdata, imread, load, matfile, mmfileinfo, open, readtable, type, VideoReader, xlsfinfo, xlsread, xmlread, and xslt.

List of MathWorks products possibly required by files, returned as a structure or array of structures. Each product is described by name (Name field), version (Version field), product number (ProductNumber field), and a certainty indicator (Certain field). The Certain field has a value of 1 if matlab.codetools.requiredFilesAndProducts determines the product is required by the specified program files, files, or a value of 0 if the product is possibly required.

The matlab.codetools.requiredFilesAndProducts function is intended to provide you with information to pass on to consumers of your MATLAB program files. The version numbers indicate the version of the products you have installed when you execute the function. Version is not an indicator of backward compatibility.

Version History

Introduced in R2014a