Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

S-function with dynamically sized matrix and vector inputs

189 views
Skip to first unread message

Thomas Marullo

unread,
Sep 27, 2011, 4:10:32 PM9/27/11
to
I am trying to create an S-function with input 0 as a dynamically sized matrix MxM and input 1 as a dynamically sized vector of Mx1. I am getting errors about the ports sizes. What am I missing here?

static void mdlInitializeSizes(SimStruct *S)
{

/*Input Port 0 */
inputDimsInfo.width = DYNAMICALLY_SIZED;
ssSetInputPortDimensionInfo(S, 0, &inputDimsInfo);
ssSetInputPortMatrixDimensions( S ,0, DYNAMICALLY_SIZED, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 0, SS_DOUBLE);
ssSetInputPortDirectFeedThrough(S, 0, 1);

/*Input Port 1 */
ssSetInputPortWidth(S, 1, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 1, SS_DOUBLE);
ssSetInputPortDirectFeedThrough(S, 1, 1);

/*Output Port 1*/
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
ssSetOutputPortDataType(S, 0, SS_DOUBLE);

Steven_Lord

unread,
Sep 28, 2011, 9:48:26 AM9/28/11
to


"Thomas Marullo" <tm...@lehigh.edu> wrote in message
news:j5tajo$b9i$1...@newscl01ah.mathworks.com...
> I am trying to create an S-function with input 0 as a dynamically sized
> matrix MxM and input 1 as a dynamically sized vector of Mx1. I am getting
> errors about the ports sizes. What am I missing here?

What is the FULL and EXACT text of the error messages you received?

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Thomas Marullo

unread,
Sep 28, 2011, 10:06:28 AM9/28/11
to
"Steven_Lord" <sl...@mathworks.com> wrote in message <j5v8ja$gri$1...@newscl01ah.mathworks.com>...
"Error in port widths or dimensions. Invalid dimension has been specified for input port 1 of 'untitled1/S-Function'."

"Error in port widths or dimensions. Output port 1 of 'untitled1/Constant' is a [3x3] matrix."

Input 1 is a 3x3. Input 2 is [1 2 3]. Output is a To Workspace block.

Syed Bilal Mehdi

unread,
Jul 20, 2012, 2:09:17 AM7/20/12
to
This thread is dead by now. But for anyone who gets the same problem, and stumbles upon this post, I am posting the solution that worked for me. I found the solution was to add the following code (ref: http://www.mathworks.com/help/toolbox/simulink/sfg/f4-30616.html)


#if defined(MATLAB_MEX_FILE)
#define MDL_SET_INPUT_PORT_DIMENSION_INFO
static void mdlSetInputPortDimensionInfo(SimStruct *S,
int_T port,
const DimsInfo_T *dimsInfo)
{
if(!ssSetInputPortDimensionInfo(S, port, dimsInfo)) return;
}
#endif
0 new messages