matlab.codetools.requiredFilesAndProducts

List dependencies of MATLAB program files

Syntax

  • fList = matlab.codetools.requiredFilesAndProducts(files) example
  • [fList, pList] = matlab.codetools.requiredFilesAndProducts(files) example
  • [fList, pList] = matlab.codetools.requiredFilesAndProducts(___,'toponly') example

Description

example

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

example

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

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 string is case insensitive.

Examples

expand all

Identify Required Files and Products for MATLAB Toolbox Function

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

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

List the required products.

{pList.Name}'
ans = 

    'MATLAB'
    'Image Processing Toolbox'

Identify Required Files and Products for Your MATLAB Program Files

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.3'
    ProductNumber: 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.3'
    ProductNumber: 1

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

Identify Top-Level Dependencies Only

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

expand all

files — List of files for analysisstring or cell array of strings

List of files for analysis, specified as a string or cell array of strings. Each string 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 report, 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

expand all

fList — List of user-authored MATLAB program filescell array of strings

List of user-authored MATLAB program files required by files, returned as a cell array of strings. Each string 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.

pList — List of MathWorks productsstructure or array of structures

List of MathWorks products required by files, returned as a structure or array of structures. Each required product is described by name (Name field), version (Version field) and product number (ProductNumber field).

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.

Was this topic helpful?