C-mex function output entire array
1 view (last 30 days)
Show older comments
Hello,
The outputs of a S function are usually defined as follows:
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T i;
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T *y = ssGetOutputPortRealSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
for (i=0; i<width; i++) {
*y++ = 2.0 *(*uPtrs[i]);
}
}
That is to say that for each timestep, an output value is calculated. For instance, we would have y.time the time values of the simulation and y.signals.values the values corresponding to each time value.
But I would like to do something different. Like:
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T *y = ssGetOutputPortRealSignal(S,0);
int Number=15;
double* var = (double*)malloc(Nptsfreq*sizeof(double)); // array of variable size
// Calculate the content of var
// Output the entire array var at each time step
}
Currently I am only able to assign ONE value of the array var to the ouput by doing *y=var[0] (here for instance the first value).
Moreover, the size of var varies at each new timestep. All I want is to output all the content of var using the output port (it is important that the information is contained in the output port since I need to use the function with ControlDesk). Is this possible?
Thank you :)
0 Comments
Answers (4)
Kaustubha Govind
on 11 Sep 2013
Signals that change size at run-time are called variable-size signals in Simulink. Please read Variable-Size Signal Basics to understand more about them. You may want to look at C S-Function with Variable-Size Signals for an example of how to output a variable-size signal from your S-function.
0 Comments
Alex
on 12 Sep 2013
1 Comment
Kaustubha Govind
on 19 Sep 2013
Alex: Please post follow-up questions as comments, rather than as answers.
From what I understand, variable-size signals is exactly what you need (not sure why you disagree). You can set the output port width at each time-step using ssSetCurrentOutputPortDimensions as in the example that I linked to.
See Also
Categories
Find more on String in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!