主要内容

engEvalString (C)

Evaluate expression in string

C Syntax

#include "engine.h"
int engEvalString(Engine *ep, const char *string);

Description

engEvalString evaluates the expression contained in string for the MATLAB® engine session, ep, previously started by engOpen.

UNIX Operating System

On a UNIX® system, engEvalString sends commands to the MATLAB workspace by writing down a pipe connected to the MATLAB stdin process. MATLAB reads back from stdout any output resulting from the command that ordinarily appears on the screen, into the buffer defined by engOutputBuffer.

To turn off output buffering in C, use:

engOutputBuffer(ep, NULL, 0);

Microsoft Windows Operating System

On a Windows® system, engEvalString communicates with MATLAB using a Component Object Model (COM) interface.

Note

The matlab::engine::MATLABEngine.eval function in the MATLAB Engine API for C++ is recommended over engEvalString. The MATLAB Engine API for C++ includes modern C++ features for writing engine applications. For more information, see Call MATLAB from C++. There are no plans to remove engEvalString or the Engine API for C.

Input Arguments

expand all

Pointer to engine, specified as Engine *.

Expression to evaluate, specified as const char *.

Output Arguments

expand all

Status, returned as int. The function returns 1 if the engine session is no longer running or the engine pointer is invalid or NULL. Otherwise, returns 0 even if the MATLAB engine session cannot evaluate the command.

Examples

Evaluate MATLAB Function in C Engine Application on Windows

This C code shows how to pass MATLAB commands to plot data on a Windows system.

 engwindemo.c

Evaluate MATLAB Function in C Engine Application on Linux or macOS

This C code shows how to pass MATLAB commands to plot data on a Linux® or macOS system.

 engdemo.c

Version History

Introduced before R2006a