core/matlab/examples/mex/mexevalstring.c

00001 /*=================================================================
00002  * mexevalstring.c
00003  *
00004  * mexevalstring takes no input arguments. It uses mexEvalString to
00005  * turn warnings off in MATLAB. It then calls mexEvalString to
00006  * evaluate 0/0, which would cause a Divide By Zero warning to be
00007  * displayed if warnings were not turned off.
00008  *
00009  * NOTE: The call to mexEvalString to evaluate a divide by zero is for
00010  * illustration purposes only, and may be replaced with a call to
00011  * mexCallMATLAB to evaluate a MATLAB function that would cause a
00012  * warning.
00013  *
00014  * Copyright 1984-2006 The MathWorks, Inc.
00015  *================================================================*/
00016 
00017 /* $Revision: 1.1 $ */
00018 #include "mex.h"
00019 
00020 void
00021 mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
00022 {
00023     (void) plhs;      /* unused parameters */
00024     (void) prhs;
00025 
00026     /* Check for proper number of input and output arguments */    
00027     if (nrhs != 0) {
00028         mexErrMsgTxt("No input arguments required.");
00029     } 
00030     if(nlhs > 1){
00031         mexErrMsgTxt("Too many output arguments.");
00032     } 
00033 
00034     /* Issue a division by 0 to show warning is displayed. */
00035     mexEvalString("a=0/0");
00036    
00037     /* Turn divideByZero warning off */
00038     mexEvalString("warnState = warning('off','MATLAB:divideByZero');");
00039     
00040     /* Issue a division by 0 to show no warning is displayed. */
00041     mexEvalString("b=0/0");
00042     
00043     /* Leave MATLAB in the same state it was in before the MEX-file
00044        executed. */
00045     mexEvalString("warning(warnState);");
00046 
00047 }

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy