Main Content

%#exclude

Ignore file or function dependencies during MATLAB Compiler dependency analysis

Since R2020a

Description

example

%#exclude fileOrFunction1 [fileOrFunction2 ... fileOrFunctionN] pragma informs the compiler that the specified files or functions need to be excluded from dependency analysis during compilation. The pragma also suppresses the compile-time warning that the files or functions cannot be compiled.

Examples

collapse all

Use isdeployed with the %#exclude pragma to suppress compile-time warnings for the non-deployable function edit.

if ~isdeployed
    %#exclude edit
    edit('readme.txt');
end

The ~isdeployed statement prevents the code from being invoked in the deployed component. The %#exclude pragma suppresses the warning that edit cannot be compiled.

Create a MATLAB® function that uses pragmas to include and exclude files.

  1. Write a function named testExclusion that uses two pragmas.

    function testExclusion()
    
    %#exclude foo.mat
    load foo.mat
    load bar.mat
    
    %#function foo.txt
    fid = fopen('foo.txt');
    fclose(fid)

    The %#exclude pragma informs the compiler to exclude the file foo.mat during compilation.

    The %#function pragma informs the compiler that the file foo.txt should be included in the compilation.

  2. Compile the function into a standalone application using mcc. The -m option builds a standalone executable. The -a option adds files to the deployable archive. The -X option instructs mcc to ignore data files during dependency analysis.

    Executing mcc -m testExclusion.m results in:

    • bar.mat and foo.txt being included during dependency analysis

    • foo.mat being excluded

    Executing mcc -m testExclusion.m -X results in:

    • foo.txt being included during dependency analysis

    • bar.mat and foo.mat being excluded

    Executing mcc -m testExclusion.m -X -a foo.mat results in:

    • foo.mat and foo.txt being included during dependency analysis

    • bar.mat being excluded

    In the last case, the -a option takes precedence over the %#exclude pragma.

Version History

Introduced in R2020a