Products & Services Industries Academia Support User Community Company

Learn more about Simulink   

mdlInitializeSizes - Specify the number of inputs, outputs, states, parameters, and other characteristics of the S-function

Required

Yes

C Syntax

#define MDL_INITIAL_SIZES
void mdlInitializeSizes(SimStruct *S)

C Arguments

S

SimStruct representing an S-Function block.

M Syntax

setup(s)

M Arguments

s

Instance of Simulink.MSFcnRunTimeBlock class representing the Level-2 M-File S-Function block.

C Description

This is the first S-function callback methods that the Simulink engine calls. This method performs the following tasks:

Dynamically Sized Block Features

You can set the parameters NumContStates, NumDiscStates, NumInputs, NumOutputs, NumRWork, NumIWork, NumPWork, NumModes, and NumNonsampledZCs to a fixed nonnegative integer or tell the Simulink engine to size them dynamically:

M Description

The Level-2 M-file S-function setup method performs nearly the same tasks as the C MEX S-function mdlInitializeSizes method, with two significant differences. The setup method does not initialize discrete state information, but it does specify the block sample times, eliminating the need for an mdlInitializeSampleTimes method. Use the following properties and methods of the run-time object s to configure the S-function:

See Using the setup Method for additional information and examples using the setup method.

C Example

static void mdlInitializeSizes(SimStruct *S)
{
    int_T nInputPorts  = 1;  /* number of input ports  */
    int_T nOutputPorts = 1;  /* number of output ports */
    int_T needsInput   = 1;  /* direct feedthrough     */

    int_T inputPortIdx  = 0;
    int_T outputPortIdx = 0;

    ssSetNumSFcnParams(S, 0);  /* Number of expected parameters */
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
        /*
         * If the number of expected input parameters is not
         * equal to the number of parameters entered in the 
         * dialog box, return. The Simulink engine generates an
         * error indicating that there is aparameter mismatch.
         */
        return;
    }else {
		     mdlCheckParameters(S);

		     if (ssGetErrorStatus(s) != NULL)
		        return;
	   }


    ssSetNumContStates(    S, 0);
    ssSetNumDiscStates(    S, 0);


    /*
     * Configure the input ports. First set the number of input
     * ports. 
     */
    if (!ssSetNumInputPorts(S, nInputPorts)) return;    
    /*
     * Set input port dimensions for each input port index 
     * starting at 0.

    */
     if(!ssSetInputPortDimensionInfo(S, inputPortIdx,
        DYNAMIC_DIMENSION)) return;
    /*
     * Set direct feedthrough flag (1=yes, 0=no).
     */
    ssSetInputPortDirectFeedThrough(S, inputPortIdx, needsInput);

    /*
     * Configure the output ports. First set the number of 
     * output ports.
     */
    if (!ssSetNumOutputPorts(S, nOutputPorts)) return;

    /*
     * Set output port dimensions for each output port index 
     * starting at 0.
     */
    if(!ssSetOutputPortDimensionInfo(S,outputPortIdx,
        DYNAMIC_DIMENSION)) return;

    /*
     * Set the number of sample times.     */
    ssSetNumSampleTimes(S, 1);   

    /*
     * Set size of the work vectors.
     */
    ssSetNumRWork(S, 0);   /* real vector    */
    ssSetNumIWork(S, 0);   /* integer vector */
    ssSetNumPWork(S, 0);   /* pointer vector */
    ssSetNumModes(S, 0);   /* mode vector    */
    ssSetNumNonsampledZCs(S, 0);   /* zero crossings */

    ssSetOptions(S, 0);

} /* end mdlInitializeSizes */

Languages

C, C++, M

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS