Вы находитесь на странице: 1из 6

createRequiredFunctionPragmasFile

Create a file containing function pragmas of dependent files

Summary
If an application compiled into a standalone app using the mcc command has protected functions
(pcode) as dependencies, the mcc command will fail to pick up these dependencies. You can use the
function createRequiredFunctionPragmasFile to analyze your application and create a file
having function pragmas to those protected functions. The resulting file when used with the mcc
command will now have the full set of dependencies.

Syntax
createRequiredFunctionPragmasFile(pragmafilename,mfile)
createRequiredFunctionPragmasFile(pragmafilename,{mfile1,...,mfileN})
createRequiredFunctionPragmasFile(pragmafilename,mydir)
createRequiredFunctionPragmasFile(pragmafilename,{mydir1,...,mydirN})

Description
createRequiredFunctionPragmasFile(pragmafilename,mfile) creates a file
containing function pragmas by analyzing a single MATLAB® file.
createRequiredFunctionPragmasFile(pragmafilename,{mfile1,...,mfileN})
creates a file containing function pragmas by analyzing multiple MATLAB® files.

createRequiredFunctionPragmasFile(pragmafilename,mydir) creates a function


pragma file by analyzing a directory.
createRequiredFunctionPragmasFile(pragmafilename,{mydir1,...,mydirN})
creates a function pragma file by analyzing multiple directories.

Examples
Create a file containing function pragmas by analyzing a single MATLAB® file
1. Create a function called mymagic.m .

function m = mymagic(in)
m = magic(in);

2. Use the function createRequiredFunctionPragmasFile to create a file having


function pragmas of dependent files.
createRequiredFunctionPragmasFile('myPragmaFile.m','mymagic.m');

You will see the function pragmas of the dependent files in the file myPragmaFile.m .

Patents | Trademarks
© 1994-2017 The MathWorks, Inc.
Page 1 of 6
%#function gpuArray
%#function magic
%#function mymagic

3. Convert the function mymagic.m into a protected function file using the MATLAB pcode
function.

>> pcode('mymagic.m')

4. Delete the function mymagic.m .

5. Create another function called myapp.m that calls the function mymagic.p .
function out = myapp(in)
if ischar(in)
in = str2double(in);
end
out = mymagic(in)

6. Create a standalone application of the myapp.m function using the mcc command.

>> mcc -m myapp.m -a myPragmaFile.m

The mcc command will create a standalone app with necessary dependencies due to the
function pragma file.

Create a file containing function pragmas by analyzing multiple MATLAB® files


1. Create a function called mymagic.m .

function m = mymagic(in)
m = magic(in);

2. Create another function called mypascal.m .

function n = mypascal(in)
n = pascal(in);

3. Use the function createRequiredFunctionPragmasFile to create a file containing


function pragmas of dependent files.
>>
createRequiredFunctionPragmasFile('myPragmaFile.m',{'mymagic.m','
mypascal.m'})

You will see the function pragmas of the dependent files in the file myPragmaFile.m .

Patents | Trademarks
© 1994-2017 The MathWorks, Inc.
Page 2 of 6
%#function gpuArray
%#function magic
%#function mymagic
%#function mypascal
%#function pascal

4. Convert the functions mymagic.m and mypascal.m into protected function files using the
MATLAB pcode function.

>> pcode('mymagic.m','mypascal.m')

5. Delete the functions mymagic.m and mypascal.m .

6. Create a function called myapp.m that calls the functions mymagic.p and mypascal.p .
function [out1,out2] = myapp(in)
if ischar(in)
in = str2double(in);
end
out1 = mymagic(in)
out2 = mypascal(in)

7. Create a standalone application of the myapp.m function using the mcc command.

>> mcc -m myapp.m -a myPragmaFile.m

The mcc command will create a standalone app with necessary dependencies due to the
function pragma file.

Create a file containing function pragmas by analyzing a single directory


1. Create a new directory in your work folder.
>> mkdir('mydir')

2. Create a function called mymagic.m and save it in the newly created directory mydir.

function m = mymagic(in)
m = magic(in);

3. Create another function called mypascal.m and save it in the newly created directory mydir.

function n = mypascal(in)
n = pascal(in);

4. The mydir folder should now have the following files:

Patents | Trademarks
© 1994-2017 The MathWorks, Inc.
Page 3 of 6
mydir
|-mymagic.m
|-mypascal.m

5. From the parent directory of the mydir folder, use the function
createRequiredFunctionPragmasFile to create a file containing function pragmas of
dependent files.

>> createRequiredFunctionPragmasFile('myPragmaFile.m','mydir')

You will see the function pragmas of the dependent files in the file myPragmaFile.m .
%#function gpuArray
%#function magic
%#function mymagic
%#function mypascal
%#function pascal

This list is the same as that of the second example.

6. Switch to the mydir folder.

>> cd mydir

7. Convert the functions mymagic.m and mypascal.m into protected function files using the
MATLAB pcode function.

>> pcode('mymagic.m','mypascal.m')

8. Delete the functions mymagic.m and mypascal.m .

9. Switch back to the parent directory of the mydir folder.

>> cd ..

10. Add the folder mydir to the MATLAB path.

>> addpath('mydir')

11. Create a function called myapp.m that calls the functions mymagic.p and mypascal.p .
function [out1,out2] = myapp(in)
if ischar(in)
in = str2double(in);
end
out1 = mymagic(in)
out2 = mypascal(in)

Patents | Trademarks
© 1994-2017 The MathWorks, Inc.
Page 4 of 6
12. Create a standalone application of the myapp.m function using the mcc command.

>> mcc -m myapp.m -a myPragmaFile.m

The mcc command will create a standalone app with necessary dependencies due to the
function pragma file.

Create a file containing function pragmas by analyzing multiple directories


1. Create two new directories in your work folder with the names mydir1 and mydir2.

>> mkdir mydir1


>> mkdir mydir2

2. Create the same MATLAB functions mymagic.m and mypascal.m mentioned in the second
and third examples and include the files in mydir1 and mydir2 as follows:

mydir1
|- mymagic.m

mydir2
|-mypascal.m

3. From the parent directory of mydir1 and mydir2, use the function
createRequiredFunctionPragmasFile to create a file containing function pragmas of
dependent files.
>> createRequiredFunctionPragmasFile('myPragmaFile.m',{'mydir1',
'mydir2'})

You will see the function pragmas of the dependent files in the file myPragmaFile.m .
%#function gpuArray
%#function magic
%#function mymagic
%#function mypascal
%#function pascal
This list is the same as seen in example two and three.

4. Switch to the directory mydir1 and convert the functions mymagic.m into a protected
function file using the MATLAB pcode function.

>> pcode('mymagic.m')

5. Delete the function mymagic.m.

6. Switch to the directory mydir2 and convert the function mypascal.m into a protected
function file using the MATLAB pcode function.
>> pcode('mypascal.m')

Patents | Trademarks
© 1994-2017 The MathWorks, Inc.
Page 5 of 6
7. Delete the function mypascal.m.

8. Switch to the parent directory of the mydir2 and mydir1 folders.

>> cd ..

9. Create a function called myapp.m that calls the functions mymagic.p and mypascal.p .
function [out1,out2] = myapp(in)
if ischar(in)
in = str2double(in);
end
out1 = mymagic(in)
out2 = mypascal(in)

10. Add the folders mydir1 and mydir2 to the MATLAB path.

>> addpath('mydir1', 'mydir2')

11. Create a standalone application of the myapp.m function using the mcc command.

>> mcc -m myapp.m -a myPragmaFile.m

The mcc command will create a standalone app with necessary dependencies due to the
function pragma file.

Input Arguments
pragmafilename — File name

File name specified as a character vector.

mfile — MATLAB file being analyzed for function pragmas

File name specified as a character vector.

{mfile1,...,mfileN}— File names

Multiple file names specified as a cell array of character vectors.

mydir — Directory name

{mydir1,...,mydirN}— Directory names

Multiple directory names specified as a cell array of character vectors.

Patents | Trademarks
© 1994-2017 The MathWorks, Inc.
Page 6 of 6

Вам также может понравиться