| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Compiler |
| Contents | Index |
| Learn more about MATLAB Compiler |
Informs MATLAB® Compiler™ that the implementation of the MATLAB function containing this pragma is supplied by the user as a C/C++ file.
%#external
This pragma affects only the single function in which it appears, and any MATLAB function can contain this pragma (local, global, private, or method).
If you compile a program that contains the %#external pragma, you must explicitly pass each file that contains this pragma on the mcc command line. mcc also expects a .c or .cpp file with the implementation to be passed in.
This pragma is not executed in MATLAB. It is treated as a comment. Only the MATLAB code is executed.
When you use this pragma, MATLAB Compiler generates an additional header file called function_name_external.h. In this header file, function_name is the name of the initial MATLAB function containing the %#external pragma. This header file contains the extern declaration of the function that the user must provide. This function must conform to the same interface as code generated by MATLAB Compiler.
In this example, the collect function calls a user-supplied helper function called collect_one, implemented in C/C++.
function collect
y = zeros(1,100); % pre-allocate the matrix
for i = 1:100
y(i) = collect_one;
end
function y = collect_one
%#EXTERNAL
persistent t;
if (isempty(t))
t = 0;
else
t = t+0.05;
end
y = sin(t);
For complete examples, see Interfacing M-Code to C/C++ Code.
![]() | Functions — Alphabetical List | %#function | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |