User`s guide

4 Stand-Alone Applications
4-42
mlfPrintMatrix is one of the many routines in the MATLAB Math Built-In
Library, which is part of the MATLAB Math Library product.
Finally,
mrankp must free the heap memory allocated to hold matrices and call
the Compiler-generated termination function.
mxDestroyArray(N);
mxDestroyArray(R);
PkgTerminate();/* Terminate the library of M-functions */
Advanced C Example
This section illustrates an advanced example of how to write C code that calls
a compiled M-file. Consider a stand-alone application whose source code
consists of two files:
multarg.m, which contains a function named multarg.
multargp.c, which contains a C function named main.
multarg.m specifies two input parameters and returns two output parameters.
function [a,b] = multarg(x,y)
a = (x + y) * pi;
b = svd(svd(a));
Thecodeinmultargp.c callsmlfMultarg andthendisplays thetwovaluesthat
mlfMultarg returns.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "matlab.h"
#include "multpkg.h"/* Include Compiler-generated header file */
static void PrintHandler( const char *text )
{
printf(text);
}
int main( ) /* Programmer written coded to call mlfMultarg */
{
#define ROWS 3
#define COLS 3