core/matlab/examples/mx/mxcreatecellmatrix.c

00001 /*=================================================================
00002  * mxcreatecellmatrix.c 
00003  *
00004  * mxcreatecellmatrix takes the input arguments and places them in a
00005  * cell. It then displays the contents of the cell through a
00006  * mexCallMATLAB call.
00007  *
00008  *
00009  * This is a MEX-file for MATLAB.  
00010  * Copyright 1984-2006 The MathWorks, Inc.
00011  * All rights reserved.
00012 *=================================================================*/
00013 
00014 /* $Revision: 1.1 $ */
00015 #include "mex.h"
00016 
00017 void
00018 mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
00019 {
00020     mxArray *cell_array_ptr, *rhs[1];
00021     mwIndex i;
00022 
00023     (void)plhs;    /* unused parameter */
00024     
00025     /* Check for proper number of input and output arguments */    
00026     if (nrhs < 1) {
00027         mexErrMsgTxt("At least one input argument required.");
00028     } 
00029     if(nlhs > 1){
00030         mexErrMsgTxt("Too many output arguments.");
00031     }
00032 
00033     /* Create a nrhs x 1 cell mxArray. */ 
00034     cell_array_ptr = mxCreateCellMatrix((mwSize)nrhs,1);
00035     
00036     /* Fill cell matrix with input arguments */
00037     for( i=0; i<(mwIndex)nrhs; i++){
00038     mxSetCell(cell_array_ptr,i,mxDuplicateArray(prhs[i]));
00039     }
00040     
00041     rhs[0] = cell_array_ptr;
00042     
00043     /* Call mexCallMATLAB to display the cell */
00044     mexPrintf("\nThe contents of the created cell is:\n\n");
00045     mexCallMATLAB(0,NULL,1,rhs,"disp");
00046 }
00047 

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