User`s manual

4 Calling MATLAB from C and Fortran Programs
4-6
Examples of Calling Engine Functions
This section contains examples that illustrate how to call engine functions from
C and Fortran programs. The examples cover the following topics:
“Calling MATLAB From a C Application”
“Calling MATLAB From a Fortran Application”
“Attaching to an Existing MATLAB Session”
It is important to understand the sequence of steps you must follow when using
the engine functions. For example, before using
engPutArray, you must create
the matrix, assign a name to it, and populate it.
After reviewing these examples, follow the instructions in “Compiling and
Linking Engine Programs” on page 4-17 to build the application and test it. By
building and running the application, you will ensure that your system is
properly configured for engine applications.
Calling MATLAB From a C Application
This program, engdemo.c, illustrates how to call the engine functions from a
stand-alone C program. For the Windows version of this program, see
engwindemo.c in the <matlab>\extern\examples\eng_mat directory. Engine
examples, like the MAT-file examples, are located in the
eng_mat directory.
/* $Revision: 1.6 $ */
/*
* engdemo.c
*
* This is a simple program that illustrates how to call the
* MATLAB engine functions from a C program.
*
* Copyright (c) 1996-2000 The MathWorks, Inc.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "engine.h"
#define BUFSIZE 256