Specifying the number of Output ports based on the input port values in the simulink S-function
Show older comments
Hello
Is there any way to specify the number of output ports based on the input port values in Simulink. I tried something as below.
static void mdlInitializeSizes(SimStruct *S) {
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 1))
return; /*Setting the number of input ports*/
/* configure input on first port*/
ssSetInputPortWidth( S, 0, 1 );
ssSetInputPortDataType( S, 0, SS_INT8 );
ssSetInputPortRequiredContiguous(S, 0, true);
ssSetInputPortDirectFeedThrough(S, 0, 1);
int n , i =0;
int *number = ( int *)ssGetInputPortSignal( S, 0 );
int num = ( int ) *number;
if(num==45)
n = 1;
else
n =0;
/* configure output ports*/
if ( !ssSetNumOutputPorts( S, n ) )
return;
}
When I try to mex the above file, it compiles but then when I try to implement in the Simulink then the MATLAB crashes(an error report is generated and I need to close it). Can any one please help me with this.
Thank you
Priyanka
Accepted Answer
More Answers (1)
Priyanka
on 11 Sep 2013
0 votes
Categories
Find more on Simulink 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!