How to reference mxArray between sFunctions with help of pWork?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I'm trying to call 'tic' and 'toc' MATLAB functions from within a sFunction Level 2. Since I want to have a rough information about the time between two calls to mdlUpdate of a block, the retirnvalue of 'tic' needs to be availale during calls.
I thought of initializing 'tic' during mdlStart, calculating 'toc' during mdlUpdate and afterwards, also in mdlUpdate, updating 'tic'. Therefore I tried to use the pWork Vector, but somehow seem to be missing something.
Whenever I try to call themxCallMATLAB() function, I get an exception, declaring 'tic' needs to be of type uint64. Therefore I think something went wrong during the pointing the pWork Vetor at the allocated mxArray.
static void mdlStart(SimStruct *S)
{
if (mxGetScalar(ssGetSFcnParam(S, SS_PARAMETER_BLOCK_TYPE)) == SS_BLOCKTYPE_CONFIG)
{
mxArray *work_vector = NULL; // mxCalloc(1, sizeof(mxArray*));
work_vector = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
mexMakeArrayPersistent(work_vector);
if(work_vector == NULL)
{ ssSetErrorStatus(S, "Faild to alloc memory for pWork Vector.\n"); }
else
{
ssSetPWorkValue(S, SS_PWORK_CONF_TIC, work_vector);
if(S->work.pWork[0] != work_vector)
{ ssSetErrorStatus(S, "[CONFBLOCK] Failed to assign PWork vector.\n"); }
// Init 'tic' value
mexCallMATLAB(1, &work_vector, 0, NULL, "tic");
}
}
}
static void mdlUpdate(SimStruct *S, int_T tid)
{
if (mxGetScalar(ssGetSFcnParam(S, SS_PARAMETER_BLOCK_TYPE)) == SS_BLOCKTYPE_CONFIG)
{
// Block Information
mxArray *tic, *elapsed;
tic = (mxArray*) ssGetPWork(S);
// tic = (mxArray*) ssGetPWorkValue(S, , SS_PWORK_CONF_TIC);
elapsed = mxCreateDoubleMatrix(1,1, mxREAL);
mexCallMATLAB(1, &elapsed, 1, &tic, "toc");
// Evaluate 'toc' result
double *secs = mxGetDoubles(elapsed);
DEBUG_MSG("[ConfigBlock] TSM_Timer_Milliseconds (%u)", milliseconds);
// Call tsm_timer
tsm_timer_milliseconds(milliseconds);
// Update _tic
mexCallMATLAB(1, &tic, 0, NULL, "tic");
}
}
2 comentarios
James Tursa
el 22 de Oct. de 2018
Is there some reason you don't want to use the C/C++ clock( ) function for this timing?
Respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!