Reviews & Opinions
Independent and trusted. Read before buy Matlab Matlab Compiler 4!

Matlab Matlab Compiler 4

Manual

Download (English)
Instruction: After click Download and complete offer, you will get access to list of direct links to websites where you can download this manual.

About

Matlab Matlab Compiler 4About Matlab Matlab Compiler 4
Here you can find all about Matlab Matlab Compiler 4 like manual and other informations. For example: review.

Matlab Matlab Compiler 4 manual (user guide) is ready to download for free.

On the bottom of page users can write a review. If you own a Matlab Matlab Compiler 4 please write about it to help other people.

 

[ Report abuse or wrong photo | Share your Matlab Matlab Compiler 4 photo ]

User reviews and opinions

<== Click here to post a new opinion, comment, review, etc.

No opinions have been provided. Be the first and add a new opinion/review.

 

Documents

doc0

The package should include the following: Your software (the standalone or shared library) The CTF archive that MATLAB Compiler created (component_name.ctf) MCRInstaller.exe, which is located in the following directory:
matlabroot\toolbox\compiler\deploy\win32
Creating a Package for Users Who Do Not Use Windows
The package should include the following: The standalone or shared library that you created with MATLAB Compiler
The CTF archive that MATLAB Compiler creates for your component
Configuring the Development Environment by Installing the MCR
To test software created by MATLAB Compiler as it will be used by end users without MATLAB, programmers must install the MCR, if it is not already installed on the development machine, and set path environment variables properly.
Configuring on Windows Platforms
1 Open the package created by you or the Deployment Tool. 2 Run MCRInstaller once on the machine where you want to develop the
application or library. MCRInstaller opens a command window and begins preparation for the installation.
3 Add the required platform-specific directories to your dynamic library path.
See Directories Required for Run-Time Deployment on page 9-5.
Configuring on Platforms Other Than Windows
1 Install the MCR by unzipping MCRInstaller.zip in a directory, for
example, /home/username/MCR. You may choose any directory except matlabroot or any subdirectory of matlabroot.
2 Copy the component and CTF archive to your application root directory, for
example, /home/username/approot.

For More Information

About This Detailed information on standalone applications Creating libraries Using the mcc command Troubleshooting Look Here Chapter 6, Standalone Applications Chapter 7, Libraries Chapter 5, Compiler Commands Chapter 8, Troubleshooting
This chapter describes the system requirements for MATLAB Compiler. It also contains installation and configuration information for all supported platforms. When you install your ANSI C or C++ compiler, you may be required to provide specific configuration details regarding your system. This chapter contains information for each platform that can help you during this phase of the installation process. Requirements (p. 2-2) Software requirements for MATLAB Compiler and a supported C/C++ compiler Steps to install MATLAB Compiler and a supported C/C++ compiler Configuring a supported C/C++ compiler to work with MATLAB Compiler Known limitations of the supported C/C++ compilers More detailed information on MATLAB Compiler options files for users who need to know more about how they work

Overview of MATLAB Compiler Technology
In this section. MATLAB Component Runtime on page 3-2 Component Technology File on page 3-2 Build Process on page 3-3

MATLAB Component Runtime

MATLAB Compiler 4 uses the MATLAB Component Runtime (MCR), which is a standalone set of shared libraries that enable the execution of M-files. The MCR provides complete support for all features of the MATLAB language.
Note Since the MCR technology provides full support for the MATLAB language, including Java, starting a compiled application takes approximately the same amount of time as starting MATLAB.
The MCR makes use of thread locking so that only one thread is allowed to access the MCR at a time. As a result, calls into the MCR are threadsafe for MATLAB Compiler generated libraries, COM objects, and.NET objects.
Component Technology File
Compiler 4 also uses a Component Technology File (CTF) archive to house the deployable package. All M-files are encrypted in the CTF archive using the Advanced Encryption Standard (AES) cryptosystem where symmetric keys are protected by 1024-bit RSA keys. Each application or shared library produced by MATLAB Compiler has an associated CTF archive. The archive contains all the MATLAB based content (M-files, MEX-files, etc.) associated with the component. When the CTF archive is extracted on a users system, the files remain encrypted.

Additional Details

Multiple CTF archives, such as COM,.NET, or Excel components, can coexist in the same user application, but you cannot mix and match the M-files they contain. You cannot combine encrypted and compressed M-files from multiple CTF archives into another CTF archive and distribute them. All the M-files from a given CTF archive are locked together with a unique cryptographic key. M-files with different keys will not execute if placed in the same CTF archive. If you want to generate another application with a different mix of M-files, you must recompile these M-files into a new CTF archive. The CTF archive and generated binary will be cleaned up following a failed compilation, but only if these files did not exist before compilation was initiated.

2 Set the path environment variables properly. See Directories Required for
Run-Time Deployment on page 9-5.
3 When you deploy a Java application to end users, they must set the class
path on the target machine. Using the MCR Installer GUI
1 When the MCR Installer wizard appears, click Next to begin the
installation. Click Next to continue.
2 In the Select Installation Folder dialog box, specify where you want to
install the MCR and whether you want to install the MCR for just yourself or others. Click Next to continue.
Note The Install MATLAB Component Runtime for yourself, or for anyone who uses this computer option is not implemented for this release. The current default is Everyone.
3 Confirm your selections by clicking Next.
The installation begins. The process takes some time due to the quantity of files that are installed. The MCRInstaller automatically: Copies the necessary files to the target directory you specified. Registers the components as needed. Updates the system path to point to the MCR binary directory, which is <target_directory>/<version>/run time/bin/win32.
4 When the installation completes, click Close on the Installation Completed

dialog box to exit.

What Software Does the End User Need?
The software required by end users depends on which of the following kinds of software is to be run by the user: Standalone Compiled Application That Accesses Shared Library on page 4-12 .NET Application on page 4-13 COM Application on page 4-14 Java Application on page 4-14 Microsoft Excel Add-In on page 4-15
Standalone Compiled Application That Accesses Shared Library
To distribute a shared library created with MATLAB Compiler to end users, create a package that includes the following files. Component

MCRInstaller.zip

Description MATLAB Component Runtime library archive; platform-dependent file that must correspond to the end users platform.

Component

Description Self-extracting MATLAB Component Runtime library utility; platform-dependent file that must correspond to the end users platform. Utility to unzip MCRInstaller.zip (optional). The target machine must have an unzip utility installed. Application

Passing Arguments to a Double-Clickable Application
On Windows, if you want to run the standalone application by double-clicking it, you can create a batch file that calls this standalone application with the specified input arguments. Here is an example of the batch file:
rem main.bat file that calls sub.exe with input parameters sub "[3]" "[6]" @echo off pause
The last two lines of code keep your output on the screen until you press a key. If you save this file as main.bat, you can run your code with the specified arguments by double-clicking the main.bat icon.
Using Graphical Applications in Shared Library Targets
When deploying a GUI as a shared library to a C/C++ application, use mclWaitForFiguresToDie to display the GUI until it is explicitly terminated.
Using the VER Function in a Compiled MATLAB Application
When you use the VER function in a compiled MATLAB application, it will perform with the same functionality as if you had called it from MATLAB. However, be aware that when using VER in a compiled MATLAB application, only version information for toolboxes which the compiled application uses will be displayed.
This chapter describes how to use MATLAB Compiler to code and build standalone applications. You can distribute standalone applications to users who do not have MATLAB on their systems. Introduction (p. 6-2) Overview of using MATLAB Compiler to build standalone applications Examples of using MATLAB Compiler to generate and deploy standalone C applications Creating standalone applications from M-files Creating applications from M-files and C or C++ code
C Standalone Application Target (p. 6-3) Coding with M-Files Only (p. 6-11) Mixing M-Files and C or C++ (p. 6-13)

Introduction

Suppose you want to create an application that calculates the rank of a large magic square. One way to create this application is to code the whole application in C or C++; however, this would require writing your own magic square, rank, and singular value routines. An easier way to create this application is to write it as one or more M-files, taking advantage of the power of MATLAB and its tools. You can create MATLAB applications that take advantage of the mathematical functions of MATLAB, yet do not require that end users own MATLAB. Standalone applications are a convenient way to package the power of MATLAB and to distribute a customized application to your users. The source code for standalone C applications consists either entirely of M-files or some combination of M-files, MEX-files, and C or C++ source code files. MATLAB Compiler takes your M-files and generates C source code functions that allow your M-files to be invoked from outside of interactive MATLAB. After compiling this C source code, the resulting object file is linked with the run-time libraries. A similar process is used to create C++ standalone applications. You can call MEX-files from MATLAB Compiler generated standalone applications. The MEX-files will then be loaded and called by the standalone code.

Note If you include compiled M-code into a larger application, you must produce a library wrapper file even if you do not actually create a separate library. For more information on creating libraries, see Chapter 7, Libraries.

Simple Example

This example involves mixing M-files and C code. Consider a simple application whose source code consists of mrank.m, mrankp.c, main_for_lib.c, and main_for_lib.h.
mrank.m contains a function that returns a vector of the ranks of the magic squares from 1 to n. function r = mrank(n) r = zeros(n,1); for k = 1:n r(k) = rank(magic(k)); end
Copy mrank.m, printmatrix.m, mrankp.c, main_for_lib.c, and main_for_lib.h into your current directory.
The steps needed to build this standalone application are
1 Compile the M-code. 2 Generate the library wrapper file. 3 Create the binary.
To perform these steps, enter the following on a single line:
mcc -W lib:libPkg -T link:exe mrank printmatrix mrankp.c main_for_lib.c
The following flow diagram shows the mixing of M-files and C-files that forms this sample standalone application. The top part of the diagram shows the mcc process and the lower part shows the mbuild process.
MATLAB Compiler generates the following C source code files: libPkg.c libPkg.h libPkg_mcc_component_data.c
This command invokes mbuild to compile the resulting MATLAB Compiler generated source files with the existing C source files (mrankp.c and main_for_lib.c) and link against the required libraries. MATLAB Compiler provides two different versions of mrankp.c in the
matlabroot/extern/examples/compiler directory:
mrankp.c contains a POSIX-compliant main function. mrankp.c sends its output to the standard output stream and gathers its input from the standard input stream. mrankwin.c contains a Windows version of mrankp.c.

mrankp.c

The code in mrankp.c calls mrank and outputs the values that mrank returns.
/* * MRANKP.C * "Posix" C main program * Calls mlfMrank, obtained by using MCC to compile mrank.m. * * $Revision: 1.1.4.32.2.3 $ * */ #include <stdio.h> #include <math.h> #include "libPkg.h" main( int argc, char **argv ) { mxArray *N; /* Matrix containing n. */ mxArray *R = NULL; /* Result matrix. */ int n; /* Integer parameter from command line.*/ /* Get any command line parameter. */ if (argc >= 2) { n = atoi(argv[1]); } else { n = 12;
} mclInitializeApplication(NULL,0); libPkgInitialize();/* Initialize library of M-Functions */ /* Create a 1-by-1 matrix containing n. */ N = mxCreateDoubleScalar(n); /* Call mlfMrank, the compiled version of mrank.m. */ mlfMrank(1, &R, N); /* Print the results. */ mlfPrintmatrix(R); /* Free the matrices allocated during this computation. */ mxDestroyArray(N); mxDestroyArray(R); libPkgTerminate(); /* Terminate library of M-functions */ mclTerminateApplication(); }

mcc -W lib:libMultpkg -T link:exe multarg printmatrix multargp.c main_for_lib.c
The program first displays the contents of a 3-by-3 matrix a, and then displays the contents of scalar b.
6.2832 +34.5575i 12.5664 +34.5575i 18.8496 +18.8496i 143.4164 25.1327 +25.1327i 31.4159 +31.4159i 37.6991 +37.6991i 43.9823 +43.9823i 50.2655 +28.2743i 56.5487 +28.2743i
Explanation of This C Code
Invoking MATLAB Compiler on multarg.m generates the C function prototype.
extern void mlfMultarg(int nargout, mxArray** a, mxArray** b, mxArray* x, mxArray* y);
This C function header shows two input arguments (mxArray* x and mxArray* y) and two output arguments (the return value and mxArray** b). Use mxCreateDoubleMatrix to create the two input matrices (x and y). Both x and y contain real and imaginary components. The memcpy function initializes the components, for example:
x = mxCreateDoubleMatrix(,ROWS, COLS, mxCOMPLEX); memcpy(mxGetPr(x), x_pr, ROWS * COLS * sizeof(double)); memcpy(mxGetPi(y), x_pi ROWS * COLS * sizeof(double));
The code in this example initializes variable x from two arrays (x_pr and x_pi) of predefined constants. A more realistic example would read the array values from a data file or a database. After creating the input matrices, main calls mlfMultarg.
mlfMultarg(2, &a, &b, x, y);
The mlfMultarg function returns matrices a and b. a has both real and imaginary components; b is a scalar having only a real component. The program uses mlfPrintmatrix to output the matrices, for example:

mlfPrintmatrix(a);

This chapter describes how to use MATLAB Compiler to create libraries. Introduction (p. 7-2) Addressing mwArrays Above the 2 GB Limit (p. 7-3) C Shared Library Target (p. 7-4) C++ Shared Library Target (p. 7-17) MATLAB Compiler Generated Interface Functions (p. 7-23) Using C/C++ Shared Libraries on Mac OS X (p. 7-32) About Memory Management and Cleanup (p. 7-38) Overview of shared libraries How to enable extended addressing for mwArrays larger than 2 GB Creating and distributing C shared libraries Creating and distributing C++ shared libraries Using MATLAB Compiler generated interface functions Preparing a Mac OS X system to use MATLAB Compiler generated libraries Recommendations on memory management
You can use MATLAB Compiler to create C or C++ shared libraries (DLLs on Windows) from your MATLAB algorithms. You can then write C or C++ programs that can call the MATLAB functions in the shared library, much like calling the functions from the MATLAB command line.

bool libtriangleInitializeWithHandlers( mclOutputHandlerFcn error_handler, mclOutputHandlerFcn print_handler )
By calling this function, you can provide your own versions of the print and error handling routines called by the MCR. Each of these routines has the same signature (for complete details, see Print and Error Handling Functions on page 7-27). By overriding the defaults, you can control how output is displayed and, for example, whether or not it goes into a log file.
Note Before calling either form of the library initialization routine, you must first call mclInitializeApplication to set up the global MCR state. See Calling a Shared Library on page 7-11 for more information.
On Microsoft Windows platforms, MATLAB Compiler generates an additional initialization function, the standard Microsoft DLL initialization function DllMain.
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, void *pv)
The generated DllMain performs a very important service; it locates the directory in which the shared library is stored on disk. This information is used to find the CTF archive, without which the application will not run. If
you modify the generated DllMain (which we do not recommend you do), make sure you preserve this part of its functionality. Library termination is simple.
void libtriangleTerminate(void)
Call this function (once for each library) before calling mclTerminateApplication.
Print and Error Handling Functions
By default, MATLAB Compiler generated applications and shared libraries send printed output to standard output and error messages to standard error. MATLAB Compiler generates a default print handler and a default error handler that implement this policy. If youd like to change this behavior, you must write your own error and print handlers and pass them in to the appropriate generated initialization function. You may replace either, both, or neither of these two functions. Note that the MCR sends all regular output through the print handler and all error output through the error handler. Therefore, if you redefine either of these functions, the MCR will use your version of the function for all the output that falls into class for which it invokes that handler. The default print handler takes the following form.
static int mclDefaultPrintHandler(const char *s)
The implementation is straightforward; it takes a string, prints it on standard output, and returns the number of characters printed. If you override or replace this function, your version must also take a string and return the number of characters handled. The MCR calls the print handler when an executing M-file makes a request for printed output, e.g., via the MATLAB function disp. The print handler does not terminate the output with a carriage return or line feed. The default error handler has the same form as the print handler.

About Memory Management and Cleanup
In this section. Overview on page 7-38 Passing mxArrays to Shared Libraries on page 7-38
Generated C++ code provides consistent garbage collection via the object destructors and the MCRs internal memory manager optimizes to avoid heap fragmentation. If memory constraints are still present on your system, try preallocating arrays in M. This will reduce the number of calls to the memory manager, and the degree to which the heap fragments.
Passing mxArrays to Shared Libraries
When an mxArray is created in an application which uses the MCR, it is created in the managed memory space of the MCR. Therefore, it is very important that you never create mxArrays (or call any other MathWorks function) before calling mclInitializeApplication. It is safe to call mxDestroyArray when you no longer need a particular mxArray in your code, even when the input has been assigned to a persistent or global variable in MATLAB. MATLAB utilizes reference counting to ensure that when mxDestroyArray is called, if another reference to the underlying data still exists, the memory will not be freed. Even if the underlying memory is not freed, the mxArray passed to mxDestroyArray will no longer be valid. For more information about mclInitializeApplication and mclTerminateApplication, see Calling a Shared Library on page 7-11.
mbuild (p. 8-2) MATLAB Compiler (p. 8-4) Deployed Applications (p. 8-8) Issues involving the mbuild utility and creating standalone applications Issues involving MATLAB Compiler Issues that appear at run time

mbuild

This section identifies some of the more common problems that might occur when configuring mbuild to create standalone applications. Options File Not Writeable. When you run mbuild -setup, mbuild makes a copy of the appropriate options file and writes some information to it. If the options file is not writeable, you are asked if you want to overwrite the existing options file. If you choose to do so, the existing options file is copied to a new location and a new options file is created. Directory or File Not Writeable. If a destination directory or file is not writeable, ensure that the permissions are properly set. In certain cases, make sure that the file is not in use. mbuild Generates Errors. If you run mbuild filename and get errors, it may be because you are not using the proper options file. Run mbuild -setup to ensure proper compiler and linker settings. Compiler and/or Linker Not Found. On Windows, if you get errors such as unrecognized command or file not found, make sure the command-line tools are installed and the path and other environment variables are set correctly in the options file. For MS Visual Studio, for example, make sure to run vcvars32.bat (MSVC 6.x and earlier) or vsvars32.bat (MSVC 7.x). mbuild Not a Recognized Command. If mbuild is not recognized, verify that matlabroot\bin is on your path. On UNIX, it may be necessary to rehash. mbuild Works from Shell But Not from MATLAB (UNIX). If the command

Note For matlabroot, substitute the MATLAB root directory on your system. Type matlabroot to see this directory name.
Path for Java Development on All Platforms
Note There are additional requirements when programming in Java. See Deploying Applications That Call the Java Native Libraries on page 5-25.
Windows Settings for Development and Testing
When programming with components that are generated with MATLAB Compiler, add the following directory to your system PATH environment variable:
UNIX Settings for Development and Testing
When programming with components that are generated with MATLAB Compiler, use the following commands to add the required platform-specific directories to your dynamic library path.

Solaris64

matlabroot/sys/os/sol64: matlabroot/bin/sol64: matlabroot/sys/java/jre/sol64/jre1.6.0/lib/sparcv9/native_threads: matlabroot/sys/java/jre/sol64/jre1.6.0/lib/sparcv9/server: matlabroot/sys/java/jre/sol64/jre1.6.0/lib/sparcv9:
matlabroot/sys/os/glnxa64: matlabroot/bin/glnxa64: matlabroot/sys/java/jre/glnxa64/jre1.6.0/lib/amd64/native_threads: matlabroot/sys/java/jre/glnxa64/jre1.6.0/lib/amd64/server:
matlabroot/sys/java/jre/glnxa64/jre1.6.0/lib/amd64:
/System/Library/Frameworks/JavaVM.framework/JavaVM: /System/Library/Frameworks/JavaVM.framework/Libraries setenv XAPPLRESDIR matlabroot>/X11/app-defaults
You can then run the compiled applications on your development machine to test them.
Directories Required for Run-Time Deployment
In this section. Path for Java Applications on All Platforms on page 9-5 Windows Path for Run-Time Deployment on page 9-5 UNIX Paths for Run-Time Deployment on page 9-6
Path for Java Applications on All Platforms
When your users run applications that contain compiled M-code, you must instruct them to set the path so that the system can find the MCR.
Note When you deploy a Java application to end users, they must set the class path on the target machine. The system needs to find.jar files containing the MATLAB libraries. To tell the system how to locate the.jar files it needs, specify a classpath either in the javac command or in your system environment variables.
Windows Path for Run-Time Deployment
The following directory should be added to the system path:
mcr_root\version\run time\win32
where mcr_root refers to the complete path where the MCR library archive files are installed on the machine where the application is to be run. Note that mcr_root is version specific; you must determine the path after you install the MCR.
UNIX Paths for Run-Time Deployment
mcr_root/version/run time/glnx86: mcr_root/version/sys/os/glnx86: mcr_root/version/sys/java/jre/glnx86/jre1.6.0/lib/i386/native_threads: mcr_root/version/sys/java/jre/glnx86/jre1.6.0/lib/i386/server: mcr_root/version/sys/java/jre/glnx86/jre1.6.0/lib/i386:

-regsvr

-setup

-U<name>

Description Verbose mode. Print the values for important internal variables after the options file is processed and all command line arguments are considered. Prints each compile step and final link step fully evaluated. Supplement or override an options file variable for variable <name>. This option is processed after the options file is processed and all command line arguments are considered. You may need to use the shells quoting syntax to protect characters such as spaces that have a meaning in the shell syntax. On Windows double quotes are used (e.g., COMPFLAGS="opt1 opt2"), and on UNIX single quotes are used (e.g., CFLAGS='opt1 opt2'). It is common to use this option to supplement a variable already defined. To do this, refer to the variable by prepending a $ (e.g., COMPFLAGS="$COMPFLAGS opt2" on Windows or CFLAGS='$CFLAGS opt2' on UNIX).
<name>=<value>
Note Some of these options (-f, -g, and -v) are available on the mcc command line and are passed along to mbuild. Others can be passed along using the -M option to mcc. For details on the -M option, see the mcc reference page.
Note MBUILD can also create shared libraries from C source code. If a file with the extension.exports is passed to MBUILD, a shared library is built. The.exports file must be a text file, with each line containing either an exported symbol name, or starting with a # or * in the first column (in which case it is treated as a comment line). If multiple.exports files are specified, all symbol names in all specified.exports files are exported.
To set up or change the default C/C++ compiler for use with MATLAB Compiler, use
To create a shared library named libfoo, use
mcc -W lib:libfoo -T link:lib foo.m
To compile and link an external C program foo.c against libfoo, use
mbuild foo.c -L. -lfoo (on UNIX) mbuild foo.c libfoo.lib (on Windows)
This assumes both foo.c and the library generated above are in the current working directory.

Invoke MATLAB Compiler

mcc [-options] mfile1 [mfile2. mfileN] [C/C++file1. C/C++fileN]
mcc is the MATLAB command that invokes MATLAB Compiler. You can issue the mcc command either from the MATLAB command prompt (MATLAB mode) or the DOS or UNIX command line (standalone mode). mcc prepares M-file(s) for deployment outside of the MATLAB
environment, generates wrapper files in C or C++, optionally builds standalone binary files, and writes any resulting files into the current directory, by default. If more than one M-file is specified on the command line, MATLAB Compiler generates a C or C++ function for each M-file. If C or object files are specified, they are passed to mbuild along with any generated C files.

Error: Unknown warning enable/disable string: warningstring. -w enable:, -w disable:, and -w error: require you to use one of the warning string identifiers listed in Warning Messages on page B-7. Error: Unrecognized option: -option. The option is not a valid option. See Chapter 10, Functions By Category for a complete list of valid options for MATLAB Compiler, or type mcc -? at the command prompt.

Warning Messages

This section lists the warning messages that MATLAB Compiler can generate. Using the -w option for mcc, you can control which messages are displayed. Each warning message contains a description and the warning message identifier string (in parentheses) that you can enable or disable with the -w option. For example, to produce an error message if you are using a demo MATLAB Compiler license to create your standalone application, you can use
mcc -w error:demo_license -mvg hello
To enable all warnings except those generated by the save command, use
mcc -w enable -w disable:demo_license.
To display a list of all the warning message identifier strings, use

mcc -w list -m mfilename

For additional information about the -w option, see Chapter 10, Functions By Category. Warning: File: filename Line: # Column: # The #function pragma expects a list of function names. (pragma_function_missing_names) This pragma informs MATLAB Compiler that the specified function(s) provided in the list of function names will be called through an feval call. This will automatically compile the selected functions. Warning: M-file "filename" was specified on the command line with full path of "pathname", but was found on the search path in directory "directoryname" first. (specified_file_mismatch) MATLAB Compiler detected an inconsistency between the location of the M-file as given on the command line and in the search path. MATLAB Compiler uses the location in the search path. This warning occurs when you specify a full pathname on the mcc command line and a file with the same base name (filename) is found earlier on the search path. This warning is issued in the following example if the file afile.m exists in both dir1 and dir2:
mcc -m -I /dir1 /dir2/afile.m
Warning: The file filename was repeated on MATLAB Compiler command line. (repeated_file) This warning occurs when the same filename appears more than once on the compiler command line. For example:
mcc -m sample.m sample.m % Will generate the warning
Warning: The name of a shared library should begin with the letters "lib". "libraryname" doesnt. (missing_lib_sentinel) This warning is generated if the name of the specified library does not begin with the letters lib. This warning is specific to UNIX and does not occur on Windows. For example:

The mwString class is a simple string class used by the mwArray API to pass string data as output from certain methods.

Constructors

mwString() mwString(const char* str) mwString(const mwString& str)

Methods

int Length() const

Operators

operator const char* () const mwString& operator=(const mwString& str) mwString& operator=(const char* str) bool operator==(const mwString& str) const bool operator!=(const mwString& str) const bool operator<(const mwString& str) const bool operator<=(const mwString& str) const
bool operator>(const mwString& str) const bool operator>=(const mwString& str) const friend std::ostream& operator<<(std::ostream& os, const

mwString& str)

mwString()
Purpose C++ Syntax Arguments Return Value Description

Construct empty string

#include "mclcppclass.h" mwString str;
Use this constructor to create an empty string.
mwString(const char* str)
Construct new string and initialize strings data with supplied char buffer
#include "mclcppclass.h" mwString str("This is a string"); str
NULL-terminated char buffer to initialize the string. None
Use this constructor to create a string from a NULL-terminated char buffer.
mwString(const mwString& str)

Purpose C++ Syntax

Copy constructor for mwString
#include "mclcppclass.h" mwString str("This is a string"); mwString new_str(str); // new_str contains a copy of the // characters in str. str mwString to be copied.
Arguments Return Value Description
Use this constructor to create an mwString that is a copy of an existing one. Constructs a new string and initializes its data with the supplied mwString.

int Length() const

Return number of characters in string
#include "mclcppclass.h" mwString str("This is a string"); int len = str.Length(); // len should be 16.
None The number of characters in the string.
Use this method to get the length of an mwString. The value returned does not include the terminating NULL character.
operator const char* () const
Return pointer to internal buffer of string
#include "mclcppclass.h" mwString str("This is a string"); const char* pstr = (const char*)str;
None A pointer to the internal buffer of the string.
Use this operator to get direct read-only access to the strings data buffer.
mwString& operator=(const mwString& str)

#include "mclcppclass.h" mwArray a(2, 2, mxDOUBLE_CLASS); mwArray b = a.Clone();
None New mwArray representing a deep copy of the original.
Use this method to create a copy of an existing array. The new array contains a deep copy of the input array.
mwArray SharedCopy() const
Return new array representing shared copy of array
#include "mclcppclass.h" mwArray a(2, 2, mxDOUBLE_CLASS); mwArray b = a.SharedCopy();
None New mwArray representing a reference counted version of the original.
Use this method to create a shared copy of an existing array. The new array and the original array both point to the same data.
mwArray Serialize() const
Serialize underlying array into byte array, and return this data in new array of type mxUINT8_CLASS
#include "mclcppclass.h" mwArray a(2, 2, mxDOUBLE_CLASS); mwArray s = a.Serialize();
None New mwArray of type mxUINT8_CLASS containing the serialized data.
Use this method to serialize an array into bytes. A 1-by-n numeric matrix of type mxUINT8_CLASS is returned containing the serialized data. The data can be deserialized back into the original representation by calling mwArray::Deserialize().
mxClassID ClassID() const

Return type of array

#include "mclcppclass.h" mwArray a(2, 2, mxDOUBLE_CLASS); mxClassID id = a.ClassID();// Should return mxDOUBLE_CLASS
None The mxClassID of the array.
Use this method to determine the type of the array. Consult the External Interfaces documentation for more information on mxClassID.

int ElementSize() const

Return size in bytes of element of array
#include "mclcppclass.h" mwArray a(2, 2, mxDOUBLE_CLASS); int size = a.ElementSize();// Should return sizeof(double)
None The size in bytes of an element of this type of array.
Use this method to determine the size in bytes of an element of array type.
Note If you define MX_COMPAT_32_OFF, this method is defined as size_t ElementSize() const.
size_t ElementSize() const
Return size in bytes of an element of array
Note If you do not define MX_COMPAT_32_OFF, this method is defined as size-t ElementSize() const.

doc1

Note: If you encounter problems relating to the installation or use of your ANSI C or C++ compiler, consult the documentation or customer support organization of your ANSI compiler vendor.
Unsupported MATLAB Platforms
The MATLAB Compiler and the MATLAB C Math Library support all platforms that MATLAB 5 supports, except for: VAX/VMS and OpenVMS The MATLAB C++ Math Library supports all platforms that MATLAB 5 supports, except for: VAX/VMS and OpenVMS Macintosh

Overview

The sequence of steps to install and configure the MATLAB Compiler so that it can generate MEX-files is:
1 Install the MATLAB Compiler. 2 Install the ANSI C/C++ compiler. 3 Configure mex to create MEX-files. 4 Verify that mex can generate MEX-files. 5 Verify that the MATLAB Compiler can generate MEX-files.
Figure 2-1 shows the sequence on all platforms. The sections following the flowchart provide more specific details for the individual platforms. Additional steps may be necessary if you plan to create stand-alone applications, however, you still must perform the steps given in this chapter first. Chapter 5, Stand-Alone External Applications, provides the details about the additional installation and configuration steps necessary for creating stand-alone applications.
Note: This flowchart assumes that MATLAB is properly installed on your system.

Install MATLAB Compiler

Use MATLAB Installer to install Toolbox (MATLAB Compiler). Follow vendors instructions to install and test ANSI C/C++ compiler.

Install ANSI Compiler

Is ANSI C/C++ compiler installed ? Yes

Configure MEX

Use mex setup to specify the options file.

Verify MEX

Test your MEX configuration.
Does the MATLAB command mex yprime.c generate proper MEX-file ? Yes 2

See MEX Troubleshooting.

Verify MATLAB Compiler can generate MEX-files
Test your MATLAB Compiler installation/configuration.
Does the MATLAB command mcc invhilb.m generate invhilb.mex ? Yes

mcc S e mfilename

After you generate your code with Real-Time Workshop, you must ensure that you have the MATLAB C Math Library installed on whatever platform you want to run the generated code.
Note: The MATLAB CompilerS option does not support the passing of parameters that is normally available with Simulink S-functions.
Specifying S-Function Characteristics

Sample Time

Similar to the MATLAB Fcn block, the automatically generated S-function has an inherited sample time. To specify a different sample time for the generated code, edit the C code file after the MATLAB Compiler generates it and set the sample time through the ssSetSampleTime function. See the Using Simulink manual for a description of the sample time settings.

Data Type

The input and output vectors for the Simulink S-function must be double-precision vectors or scalars. You must ensure that the variables you use in the M-code for input and output are also double-precision values. You can use the MATLAB Compiler assertions mbrealvector, mbrealscalar, and mbreal to guarantee that the resulting C code uses the correct data types. For more information on assertions, see Optimizing Through Assertions in Chapter 4.
Limitations and Restrictions

MATLAB Code

There are some limitations and restrictions on the kinds of MATLAB code with which the MATLAB Compiler can work. The MATLAB Compiler Version 1.2 cannot compile: Script M-files. (See page 3-12 for further details.) M-files containing eval or input. These functions create and use internal variables that only the MATLAB interpreter can handle. M-files that use the explicit variable ans. M-files that create or access sparse matrices. Built-in MATLAB functions (functions such as eig have no M-file, so they cant be compiled), however, calls to these functions are okay. Functions that are only MEX functions. Functions that use variable argument lists (varargin). M-files that use feval to call another function defined within the same file. (Note: In stand-alone C and C++ modes, a new pragma (%#function <name-list>) is used to inform the MATLAB Compiler that the specified function will be called through an feval call. See Using feval in Chapter 5 for more information.) Calls to load or save that do not specify the names of the variables to load or save. The load and save functions are supported in compiled code for lists of variables only. For example, this is acceptable:
load( filename, 'a', 'b', 'c' ); % This is OK and loads the % values of a, b, and c from % the file.
However, this is not acceptable:
load( filename, var1, var2, var3 ); % This is not allowed.

Restrictions on Stand-Alone External Applications
The restrictions and limitations noted in the previous section also apply to stand-alone external applications. In addition, stand-alone external applications cannot access: MATLAB debugging functions, such as dbclear. MATLAB graphics functions, such as surf, plot, get, and set. MATLAB exists function. Calls to MEX-file functions because the MATLAB Compiler needs to know the signature of the function. Simulink functions. Although the MATLAB Compiler can compile M-files that call these functions, the MATLAB C and C++ Math libraries do not support them. Therefore, unless you write your own versions of the unsupported routines, the linker will report unresolved external reference errors.
Converting Script M-Files to Function M-Files
MATLAB provides two ways to package sequences of MATLAB commands: Function M-files. Script M-files. These two categories of M-files differ in two important respects: You can pass arguments to function M-files but not to script M-files. Variables used inside function M-files are local to that function; you cannot access these variables from the MATLAB interpreters workspace. By contrast, variables used inside script M-files are global in the base workspace; you can access these variables from the MATLAB interpreter. The MATLAB Compiler can only compile function M-files. That is, the MATLAB Compiler cannot compile script M-files. Furthermore, the MATLAB Compiler cannot compile a function M-file that calls a script. Converting a script into a function is usually fairly simple. To convert a script to a function, simply add a function line at the top of the M-file. For example, consider the script M-file houdini.m:
m = magic(2); % Assign 2x2 matrix to m. t = m.^ 3; % Cube each element of m. disp(t); % Display the value of t.
Running this script M-file from a MATLAB session creates variables m and t in your MATLAB workspace. The MATLAB Compiler cannot compile houdini.m because houdini.m is a script. Convert this script M-file into a function M-file by simply adding a function header line:
function t = houdini() m = magic(2); % Assign 2x2 matrix to m. t = m.^ 3; % Cube each element of m. disp(t); % Display the value of t.
The MATLAB Compiler can now compile houdini.m. However, because this makes houdini a function, running houdini.mex no longer creates variable m
in the MATLAB workspace. If it is important to have m accessible from the MATLAB workspace, you can change the beginning of the function to:
function [m,t] = houdini();
Type Imputation. 4-3 Type Imputation Across M-Files. 4-3 Optimizing with Compiler Option Flags An Unoptimized Program. Optimizing with the -r Option Flag. Optimizing with the -i Option. Optimizing with a Combination of -r and -i. 4-5 4-6 4-8 4-10 4-11

[m,n] = size(a); m = m +.25;
then the MATLAB Compiler imputes the C double data type for variable m.
Note: Specifying assertions and pragmas, as described later in this chapter, can greatly assist the type imputation process.
Type Imputation Across M-Files
If an M-file calls another M-file function, the MATLAB Compiler reads the entire contents of the called M-file function as part of the type imputation
analysis. For example, consider an M-file function named profit that calls another M-file function getsales:
function p = profit(inflation) revenue = getsales(inflation);. p = revenue costs;
To impute the data types for variables p and revenue, the MATLAB Compiler reads the entire contents of the file getsales.m. Suppose you compile getsales.m to produce getsales.mex. When invoked, profit.mex calls getsales.mex. However, the MATLAB Compiler reads getsales.m. In other words, the runtime behavior of profit.mex depends on getsales.mex, but type imputations depend on getsales.m. Therefore, unless getsales.m and getsales.mex are synchronized, profit.mex may run peculiarly. To ensure the files are synchronized, recompile every time you modify an M-file.
Optimizing with Compiler Option Flags
Some MATLAB Compiler option flags optimize the generated code; other option flags generate compilation or runtime information. The two most important optimization option flags are i (suppress array boundary checking) and r (generate real variables only). Consider the squibo M-file:
function g = squibo(n) % The first n "squibonacci" numbers. g = zeros(1,n); g(1) = 1; g(2) = 1; for i = 3:n g(i) = sqrt(g(i1)) + g(i2); end
We compiled squibo.m with various combinations of performance option flags on a Pentium Pro 200 MHz workstation running Linux. Then, we ran the resulting MEX-file 10 times in a loop and measured how long it took to run. Table 4-1 shows the results of the squibo example using n equal to 10,000 and executing it 10 times in a loop.
Table 4-1: Performance for n=10000, run 10 times Compile Command Line squibo.m (uncompiled) mcc squibo mcc r squibo mcc i squibo mcc ri squibo Elapsed Time (in sec.) % Improvement
5.7446 3.7947 0.4548 2.7815 0.0625

-33.94 92.08 51.58 98.91

As you can see from the performance table, r and i have a strong influence on elapsed execution time.
In order to understand how r and i improve performance, you need to look at the MEX-file source code that the MATLAB Compiler generates. When examining the generated code, focus on two sections: The comment section that lists the MATLAB Compilers assumptions. The code that the MATLAB Compiler generates for loops. Most programs spend the vast majority of their CPU time inside loops.

An Unoptimized Program

Optimizing with the -i Option
The i option flag generates code that: Does not allow matrices to grow larger than their starting size. Does not check matrix bounds. The MATLAB interpreter allows arrays to grow dynamically. If you do not specify i, the MATLAB Compiler also generates code that allows arrays to grow dynamically. However, dynamic arrays, for all their flexibility, perform relatively slowly. If you specify i, the generated code does not permit arrays to grow dynamically. Any attempts to access an array beyond its fixed bounds will cause a runtime error. Using i reduces flexibility but also makes array access significantly cheaper. To be a candidate for compiling with i, an M-file must preallocate all arrays. Use the zeros or ones function to preallocate arrays. (Refer to the Optimizing by Preallocating Matrices section later in this chapter.)
Caution: If you fail to preallocate an array and compile with the i option, your system will behave unpredictably and may crash.
If you forget to preallocate an array, the MATLAB Compiler cannot detect the mistake; the errors do not appear until runtime. If your program crashes with an error referring to: Bus errors Memory exceptions Phase errors Segmentation violations Unexplained application errors then there is a good chance that you forgot to preallocate an array. The i option makes some MEX-files run faster, but generally, you have to use i in combination with r in order to see real speed advantages. For example, compiling squibo.m with i does not produce any speed advantages, but
compiling squibo.m with a combination of i and r creates a very fast MEX-file.
Optimizing with a Combination of -r and -i
Compiling programs with a combination of r and i produces code with all the speed advantages of both option flags. Compile with both option flags only if your M-file Contains no complex values or operations. Preallocates all arrays, and then never changes their size. Compiling squibo.m with ri produces an extremely fast version of squibo.mex. In fact, the resulting squibo.mex runs more than 98% faster than squibo.m.

Type Imputations for -ri

When compiling with r and i, the MATLAB Compiler type imputations are:
The MATLAB Compilers type imputations for ri are identical to the imputations for r alone. Additional performance improvements are due to the generated loop code.
The Generated Loop Code for -ri
The MATLAB Compiler generates the loop code:
/* for i=3:n */ for (I0_ = 3; I0_ <= n; I0_ = I0_ + 1) { i = I0_; /* g(i) = sqrt(g(i-1)) + g(i-2); */ R0_ = sqrt((mccPR(&g)[((i-1)-1)])); mccPR(&g)[(i-1)] = (R0_ + (mccPR(&g)[((i-2)-1)])); /* end */ }

Note: The options file is stored in the MATLAB subdirectory of your home directory. This allows each user to have a separate mbuild configuration.
Changing Compilers. If you want to change compilers or switch between C and C++, use the mbuild setup command and make the desired changes.

Verifying mbuild

There is C source code for an example, ex1.c included in the <matlab>/extern/examples/cmath directory, where <matlab> represents the top-level directory where MATLAB is installed on your system. To verify that mbuild is properly configured on your system to create stand-alone applications, copy ex1.c to your local directory and cd to that directory. Then, at the MATLAB prompt, enter:

mbuild ex1.c

This should create the file called ex1. Stand-alone applications created on UNIX systems do not have any extensions.
Locating Shared Libraries. Before you can run your stand-alone application, you must tell the system where the API and C/C++ shared libraries reside. This table provides the necessary UNIX commands depending on your systems architecture.

Architecture

Command setenv SHLIB_PATH <matlab>/extern/lib/hp700:$SHLIB_PATH setenv LIBPATH <matlab>/extern/lib/ibm_rs:$LIBPATH setenv LD_LIBRARY_PATH <matlab>/extern/lib/$Arch:$LD_LIBRARY_PATH
HP700 IBM RS/6000 All others

where:

<matlab> is the MATLAB root directory $Arch is your architecture (i.e., alpha, lnx86, sgi, sgi64, sol2, or sun4)
It is convenient to place this command in a startup script such as ~/.cshrc. Then the system will be able to locate these shared libraries
automatically, and you will not have to re-issue the command at the start of each login session.
Note: On all UNIX platforms (except Sun4), the compiler library is shipped as a shared object (.so) file. Any compiler-generated, stand-alone application must be able to locate the C/C++ libraries along the LD_LIBRARY_PATH environment variable in order to be found and loaded. Consequently, to share a compiler-generated, stand-alone application with another user, you must provide all of the required shared libraries. For more information about the required shared libraries for UNIX, see Distributing Stand-Alone UNIX Applications.
Running Your Application. To launch your application, enter its name on the
command line. For example,

ex1 ans = 5 6

ans = 1.0000 + 7.0000i 2.0000 + 8.0000i 3.0000 + 9.0000i 4.0000 +10.0000i 5.0000 +11.0000i 6.0000 +12.0000i
Verifying the MATLAB Compiler
There is MATLAB code for an example, hello.m, included in the <matlab>/extern/examples/compiler directory. To verify that the MATLAB Compiler can generate stand-alone applications on your system, type the following at the MATLAB prompt:

The mbuild script provides a convenient and easy way to configure your ANSI compiler with the proper switches to create an application. To configure your compiler, use
Run mbuild with the setup option from either the MATLAB or DOS command prompt. The setup switch creates an options file for your ANSI compiler. You must run mbuild setup before you create your first stand-alone application; otherwise, when you try to create a stand-alone application, you will get the message
Sorry! No options file was found for mbuild. The mbuild script must be able to find an options file to define compiler flags and other settings. The default options file is $script_directory\\$OPTFILE_NAME. To fix this problem, run the following: mbuild setup This will configure the location of your compiler.
Executing the setup option presents a list of compilers whose options files are currently included in the bin subdirectory of MATLAB. This example shows how to select the Microsoft Visual C++ compiler:
mbuild setup Welcome to the utility for setting up compilers for building math library applications files. Choose your default Math Library: [1] MATLAB C Math Library [2] MATLAB C++ Math Library Math Library: 1 Choose your C/C++ compiler: [1] Borland C/C++ (version 5.0) [2] Microsoft Visual C++ (version 4.2 or version 5.0) [3] Watcom C/C++ (version 10.6 or version 11.0) [0] None compiler: 2
If we support more than one version of the compiler, you are asked for a specific version. For example,
Choose the version of your C/C++ compiler: [1] Microsoft Visual C++ 4.2 [2] Microsoft Visual C++ 5.0 version: 2
Next, you are asked to enter the root directory of your ANSI compiler installation:
Finally, you must verify that the information is correct:
Please verify your choices: Compiler: Microsoft Visual C++ 5.0 Location: c:\msdev Library: C math library Are these correct?([y]/n): y Default options file is being updated.
If you respond to the verification question with n (no), you get a message stating that no compiler was set during the process. Simply run mbuild setup once again and enter the correct responses for your system.
Changing Compilers. If you want to change your ANSI (system) compiler, make other changes to its options file (e.g., change the compilers root directory), or switch between C and C++, use the mbuild setup command and make the desired changes.
There is C source code for an example, ex1.c included in the <matlab>\extern\examples\cmath directory, where < matlab> represents the top-level directory where MATLAB is installed on your system. To verify that mbuild is properly configured on your system to create stand-alone applications, enter at the MATLAB prompt:

Build an executable with debugging symbols included. Help; prints a description of mbuild and the list of options. Include <pathname> in the compiler include search path. Override options file setting for variable <name>. No execute flag. This option causes the commands used to compile and link the target to display without executing them. Create an executable named <name>.
Table 5-3: mbuild Options on Macintosh (Continued) Option O setup Description
Build an optimized executable. Set up default options file. This switch should be the only argument passed. Verbose; print all compiler and linker settings.
If you need to customize the application building process, use the verbose switch, v, as in:
mbuild v filename.m [filename1.m filename2.m ]
to generate a list of all the current compiler settings. After you determine the desired changes that are necessary for your purposes, use an editor to make changes to the options file that corresponds to your compiler. You can also use the settings obtained from the verbose switch to embed them into an IDE or makefile that you need to maintain outside of MATLAB.
Distributing Stand-Alone Macintosh Applications
To distribute a stand-alone application, you must include the applications executable as well as the shared libraries with which the application was linked against. These lists show which files should be included on the Power Macintosh and 68K Macintosh systems:
Application (executable) libmmfile libmatlb libmcc libmx libut
Application (executable) libmmfile.o libmatlb.o libmcc.o libmx.o libut.o For example, to distribute the Power Macintosh version of the ex1 example, you need to include ex1, libmmfile, libmatlb, libmcc, libmx, and libut. To distribute the 68K Macintosh version of the ex1 example, you need to include ex1, libmmfile.o, libmatlb.o, libmcc.o, libmx.o, and libut.o.

Troubleshooting mbuild

This section identifies some of the more common problems that might occur when configuring mbuild to create stand-alone external applications.
Options File Not Writable
When you run mbuild setup, mbuild makes a copy of the appropriate options file and writes some information to it. If the options file is not writable, the process will terminate and you will not be able to use mbuild to create your applications.
Directory or File Not Writable
If a destination directory or file is not writable, ensure that the permissions are properly set. In certain cases, make sure that the file is not in use.

mbuild Generates Errors

On UNIX, if you run mbuild filename and get errors, it may be because you are not using the proper options file. Run mbuild setup to ensure proper compiler and linker settings.
Compiler and/or Linker Not Found
On Windows, if you get errors such as unrecognized command or file not found, make sure the command line tools are installed and the path and other environment variables are set correctly.

Compiling mrank.m and rank.m as Helper Functions
Another way of building the mrank external application is to compile rank.m and mrank.m as helper functions to main.m. In other words, instead of invoking the MATLAB Compiler three separate times, invoke the MATLAB Compiler only once. For C:

mcc e main mrank rank

mcc e h main

For C++:

mcc p main mrank rank

mcc p h main

These commands create a single file (main.c) of C or C++ source code. Files built with helper functions run slightly faster.
Note: Each of these commands automatically invoke mbuild because main.m is explicitly included on the command line.

Print Handlers

A print handler is a routine that controls how your application displays the output generated by mlf calls. If you do not register a print handler, the system provides a default print handler for your application. The default print handler writes output to the standard output stream. You can override this behavior, however, by registering an alternative print handler. In fact, if you are coding a stand-alone external application with a GUI, then you must register an alternative print handler. This makes it possible for application output to be displayed inside a GUI mechanism, such as a Windows message box or a Motif Label widget. If you create a print handler routine, you must register its name at the beginning of your stand-alone external application. The way you establish a print handler depends on whether or not your source code is written entirely as function M-files.
Note: The print handlers discussed in this section work for C++ as well as C applications. However, we recommend that you use different print handlers for C++ applications. See the MATLAB C++ Math Library Users Guide for details about C++ print handlers.
Source Code Is Not Entirely Function M-Files
If some (or all) of your stand-alone external application is coded in C (as opposed to being written entirely as function M-files), then you must Register the print handler. Write a print handler. To register a print handler routine, call mlfSetPrintHandler as the first executable line in main (or WinMain). For example, the first line of mrankwin.c (a Microsoft Windows program) registers a print handler routine named WinPrint by calling mlfSetPrintHandler as
mlfSetPrintHandler(WinPrint);
Next, you must write a print handler routine. The print handler routine in mrankwin.c is
static int totalcnt = 0; static int upperlim = 0; static int firsttime = 1; char *OutputBuffer; void WinPrint( char *text) { int cnt; if (firsttime) { OutputBuffer = (char *)mxCalloc(1028, 1); upperlim += 1028; firsttime = 0; } cnt = strlen(text); if (totalcnt + cnt >= upperlim) { char *TmpOut; TmpOut = (char *)mxCalloc(upperlim + 1028, 1); memcpy(TmpOut, OutputBuffer, upperlim); upperlim += 1028; mxFree(OutputBuffer); OutputBuffer = TmpOut; } strncat(OutputBuffer, text, cnt); }

Declaring Variables

Each branch begins with a commented list of MATLAB Compiler assumptions and an uncommented list of variable declarations. For example, the imputations for the Complex Branch of fibocon.c are:
/***************** Compiler Assumptions **************** * * I0_ integer scalar temporary * fibocon <function being defined> * g complex vector/matrix * i integer scalar * n complex vector/matrix * x complex vector/matrix *******************************************************/
Variable declarations follow the assumptions. For example, the variable declarations of fibocon.c are:
mxArray mxArray mxArray int i = int I0_ g; n; x; 0; = 0
The mapping between commented MATLAB Compiler assumptions and the actual C variable declarations is:
Assumption C Type int double mxArray mxArray
Integer scalar Real scalar Complex vector/matrix Real vector/matrix
All vectors and matrices, whether real or complex, are declared as mxArray structures. All scalars are declared as simple C data types (either int or double). An int or double consumes far less space than an mxArray structure.
The MATLAB Compiler tries to preserve the variable names you specify inside the M-file. For instance, if a variable named jam appears inside an M-file, then the analogous variable in the compiled version is usually named jam. The MATLAB Compiler typically generates a few temporary variables that do not appear inside the M-file. All variables whose names end with an underscore (_) are temporary variables that the MATLAB Compiler creates in order to help perform a calculation. When coding an M-file, you should pick variable names that do not end with an underscore. For example, consider the two variable names:
hoop = 7; hoop_ = 7; % Good variable name % Bad variable name
In addition, you should pick variable names that do not match reserved words in the C language; for example:
switches = 7; switch = 7; % Good variable name % Bad variable name because switch is a C keyword
Importing Input Arguments

This pragma has no effect on C++ generated code (i.e., if the p MATLAB Compiler option flag is used).
%#inbounds is the pragma version of the MATLAB Compiler option flag i.

Placing the pragma

anywhere inside an M-file has the same effect as compiling that file with i. The %#inbounds pragma (or i) causes the MATLAB Compiler to generate C code that: Does not check array subscripts to determine if array indices are within range. Does not reallocate the size of arrays when the code requests a larger array. For example, if you preallocate a 10-element vector, the generated code cannot assign a value to the 11th element of the vector. Does not check input arguments to determine if they are real or complex. The %#inbounds pragma can make a program run significantly faster, but not every M-file is a good candidate for %#inbounds. For instance, you can only specify %#inbounds if your M-file preallocates all arrays. You typically preallocate arrays with the zeros or ones functions.
Note: If an M-file contains code that causes an array to grow, then you cannot compile with the %#inbounds option. Using %#inbounds on such an M-file produces code that fails at runtime.
Using %#inbounds means you guarantee that your code always stays within the confines of the array. If your code does not, your compiled program will probably crash.
The %#inbounds pragma applies only to the M-file in which it appears. For example, suppose %#inbounds appears in alpha.m. Given the command:

mcc alpha beta

the %#inbounds pragma in alpha.m has no influence on the way the MATLAB Compiler compiles beta.m.

See Also

mcc (the i option), %#realonly

%#ivdep

Ignore-vector-dependencies (ivdep) pragma.
This pragma has no effect on C++ generated code (i.e., if the p MATLAB Compiler option flag is used). The %#ivdep pragma tells the MATLAB Compiler to ignore vector dependencies in the assignment statement that immediately follows it. Since the %#ivdep pragma only affects a single line of an M-file, you can place multiple %#ivdep pragmas into an M-file. Using %#ivdep can speed up some assignment statements, but using %ivdep incorrectly causes assignment errors. The %#ivdep pragma borrows its name from a similar feature in many vectorizing C and Fortran compilers. This is an M-file function that does not (and should not) contain any %#ivdep pragmas:
function a = mydep a = 1:8; a(3:6) = a(1:4);
Compiling this program and then running the resulting MEX-file yields the correct answer, which is:

-u (Number of Inputs) and -y (Number of Outputs)
Allow you to exercise more control over the number of valid inputs or outputs for your function. These options specifically set the number of inputs (u) and the number of outputs (y) for your function. If either u or y is omitted, the respective input or output will be dynamically sized.

reallog

Natural logarithm for nonnegative real inputs.
Y = reallog(X) reallog is an elementary function that operates element-wise on matrices. reallog returns the natural logarithm of X. The domain of reallog is the set of all nonnegative real numbers. If X is negative or complex, reallog issues an

error message.

reallog is similar to the MATLAB log function; however, the domain of log is much broader than the domain of reallog. The domain of log includes all real and all complex numbers. If Y is real, you should use reallog rather than log
for two reasons. First, subsequent access of Y may execute more efficiently if Y is calculated with reallog rather than with log. Using reallog forces the MATLAB Compiler to impute a real type to X and Y. Using log typically forces the MATLAB Compiler to impute a complex type to Y. Second, the compiled version of reallog may run somewhat faster than the compiled version of log. (However, the interpreted version of reallog may run somewhat slower than the interpreted version of log.)
exp, log, log2, logm, log10, realsqrt

realpow

Array power function for real-only output.
Z = realpow(X,Y) realpow returns X raised to the Y power. realpow operates element-wise on matrices. The range of realpow is the set of all real numbers. In other words, if X raised to the Y power yields a complex answer, then realpow does not return an answer. Instead, realpow signals an error.
If X is negative and Y is not an integer, the resulting power is complex and realpow signals an error.
realpow is similar to the array power operator (.^) of MATLAB. However, the range of.^ is much broader than the range of realpow. (The range of.^ includes all real and all imaginary numbers.) If X raised to the Y power yields a complex answer, then you must use.^ instead of realpow. However, if X raised to the Y power yields a real answer, then you should use realpow for two reasons.
First, subsequent access of Z may execute more efficiently if Z is calculated with realpow rather than.^. Using realpow forces the MATLAB Compiler to impute that Z, X, and Y are real. Using.^ typically forces the MATLAB Compiler to impute the complex type to Z. Second, the compiled version of realpow may run somewhat faster than the compiled version of.^. (However, the interpreted version of realpow may run somewhat slower than the interpreted version of.^.)

reallog, realsqrt

realsqrt
Square root for nonnegative real inputs.
Y = realsqrt(X) realsqrt(X) returns the square root of the elements of X. The domain of realsqrt is the set of all nonnegative real numbers. If X is negative or complex, realsqrt issues an error message. realsqrt is similar to sqrt; however, sqrts domain is much broader than realsqrts. The domain of sqrt includes all real and all complex numbers. Despite this larger domain, if Y is real, then you should use realsqrt rather than sqrt for two reasons.

libraries Macintosh 7-24 Microsoft Windows 7-13 shared locating on Macintosh 5-21 locating on UNIX 5-9 locating on Windows 5-14 UNIX 7-4 libut 5-3 limitations of MATLAB Compiler 3-9 ans 3-9 cell arrays 3-9 eval 3-9 input 3-9 multidimensional arrays 3-9
MATLAB callback 4-22 Compiler 5-52 compiler default arguments 5-54 generating C++ code 5-53 Handle Graphics 5-53 Image Processing Toolbox 5-52 bestblk() 5-52 bmpread() 5-52 bmpwrite() 5-52 edge() 5-52 fspecial() 5-52 gray() 5-52 gray2ind() 5-52 grayslice() 5-52 ind2gray() 5-52 rgb2ntsc() 5-52 MATLAB API Library 1-4, 5-3 MATLAB C++ Math Library header file 7-6 MATLAB Compiler assertions 4-13 assumptions list 4-6 capabilities 1-2, 1-7 compiling MATLAB-provided M-files 5-35 creating MEX-files 1-3 directory organization Macintosh 7-22 Microsoft Windows 7-12 UNIX 7-3 generating callbacks 4-20 getting started 3-1 good M-files to compile 1-8 installing on Macintosh 2-20 installing on UNIX 2-6 installing on Windows 2-13
limitations 3-9 optimization option flags 4-5 Simulink S-function output 8-38 syntax 8-28 system requirements Macintosh 2-19 UNIX 2-5 Windows 2-13 type imputations 4-3, 4-6 verbose output 8-36 warnings output 8-36 why compile M-files? 1-8 MATLAB Compiler Library 1-4, 5-3, 9-29-18 MATLAB Compiler-compatible M-files 3-10 MEX mode 3-10 stand-alone mode 5-29 MATLAB interpreter 1-2 callbacks 4-20 data type use 4-6 dynamic matrices 4-10 pragmas 4-17 running a MEX-file 1-3 MATLAB libraries Math 1-4, 5-3 M-file Math 1-4, 4-23, 5-3, 5-35, 8-31 Utilities 1-4, 5-3 matrices dynamic 4-10 preallocating 4-27 sparse 3-9 mbint 8-16 example 4-13 mbintscalar 8-18 example 4-14 mbintvector 8-19 mbreal 8-20 example 4-14
mbrealscalar 8-21 mbrealvector 8-22 mbscalar 8-23 mbuild 5-6 mbuild options
Metrowerks CodeWarrior C/C++ 2-19, 2-20 C/C++ Pro 2-19
Macintosh 5-24 UNIX 5-11 Windows 5-18 mbuild script Macintosh 5-23 options on Macintosh 5-24 options on UNIX 5-11 options on Windows 5-18 UNIX 5-11 Windows 5-17
overview 1-3 suppressing invocation of 8-29 verifying on Macintosh 2-23 on UNIX 2-10 on Windows 2-17
Macintosh 5-21 UNIX 5-7 Windows 5-14 mbvector 8-24 mcc 8-28 mccCallMATLAB 6-15, 6-21 expense of 4-7 finding 4-21 mccComplexInit 6-9 mcc.h 6-4, 9-2 mccImport 6-9 mccImportReal 6-9 mccOnes 4-21 mccOnesMN 4-20 mccReturnFirstValue 6-10
mccSetRealVectorElement 4-9, 4-12
measurement. See timing. memory exceptions 4-10 memory usage reducing 5-29 metrics. See timing.
Macintosh 2-21 UNIX 2-8 Windows 2-15 MEX-file built from multiple M-files 4-21 bus error 2-28 comparison to external applications 5-2 compiling Macintosh 2-21 computation error 2-28 computational section 6-6 configuring 2-3 contents generated by mcc 6-36-10 creating on Macintosh 2-21 UNIX 2-7 Windows 2-15 entry point 4-22 extension Macintosh 2-23 UNIX 2-7 Windows 2-17 for code hiding 1-9 from multiple M-files 4-22 gateway routine 6-4 generating with MATLAB Compiler 2-3 invoking 3-4

 

Tags

AKP 932 LN-T4066F KX-TG7120FX Kdavx11J-KD-avx11 3180 FAX Cable KDC-3080RA VX912 Archos 404 VP-D31I Amarys 400 B1100 GPS 155 EHD72100X DT-550 DC RTS Settings CMT-BX5 TS-H1302 ZS-M35 PRO 4600 LX7000SA-22S Q5010 JSI5464E DCR-DVD602E EC140B Princess Vivacity Notebook Mosca029 A Camry Companion U-CA 5 4050TN Ryobi JM80 Opticfilm 7400 Cuisine Evolved VSA-E03 LV2798 Motorola 2500 J900MV GR-T392GVH DBX 386 MP970 W2243T-PF IMP-550 ASF645 KOT-153UB 24 E DK-7600S TX-28PK20F Cf 90 Dishwashers Cooker Roland ME-5 Fable Amex 601 PMA-560 DSC-T3 LFV1024 PG-310 SDM-S95A SPH-W2900ML MF5750 Review 5d ED IC-765 MIM 2080 NW-S705F 6842PEM PLC-XF20 WF-T652A Editor Lcdw19HD LC203 Tritonr Thermomix 3300 Iaudio F2 Kxtg1100E Keyboard Magicolor 2200 WD-14575RD Symbol P470 KNA-DV3200 Compact Vert TR ARX7570Z Sp-DVB01d-0920 UX-Y303CL RP-20CB20A MX-810 GZ-MG135 ICF-M60lrds Easymax Lowrance X125 700R-serials-001026501-thru-103029625 Windows XM-228 TV-3100 TC-14S4RP

 

manuel d'instructions, Guide de l'utilisateur | Manual de instrucciones, Instrucciones de uso | Bedienungsanleitung, Bedienungsanleitung | Manual de Instruções, guia do usuário | инструкция | návod na použitie, Užívateľská príručka, návod k použití | bruksanvisningen | instrukcja, podręcznik użytkownika | kullanım kılavuzu, Kullanım | kézikönyv, használati útmutató | manuale di istruzioni, istruzioni d'uso | handleiding, gebruikershandleiding

 

Sitemap

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101