Reply by telmatrix August 23, 20032003-08-23
Hi Ya'll,

The following code below is from the mdlOutputs routine in my C MEX
S-function. It is working well, and the question is specific to
concatenating the data that is being written to the base workspace.

Currently "data" is being "overwritten" every time-step, which is not
preferable.

One option is to perform a temporary data save (old_value) to the
global workspace, and then concatentate the new value (from the next
time-point) to the old_value. Then write this updated array to base
workspace. (This does not appear to be an optimal solution)

Does anyone know of a simple trick?
(That may circumvent usage of global workspace?)
Comments? Suggestions?

Thanks!
Jay ------------------

/* Get variable from MATLAB base workspace. */
array_ptr = mexGetVariable("base",array_name);

if (array_ptr == NULL ){
/* Since variable does not yet exist in MATLAB workspace,
create it and place it in the global workspace. */
array_ptr=mxCreateDoubleMatrix(1,1,mxREAL);
}

/*determine the starting address of the mxArray that array_ptr
points to*/
ptr = mxGetPr(array_ptr);
ptr[0] = *uPtrs[0];

/* Put variable in MATLAB base workspace */
check=mexPutVariable("base","data",array_ptr);