C-mex function output entire array
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (4 件)
Kaustubha Govind
2013 年 9 月 11 日
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 件のコメント
Alex
2013 年 9 月 12 日
1 件のコメント
Kaustubha Govind
2013 年 9 月 19 日
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.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!