Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:48:38+00:00 2026-06-07T23:48:38+00:00

I am trying to create an s-function in Simulink using s-function builder that will

  • 0

I am trying to create an s-function in Simulink using s-function builder that will accept a 2d array as an input. In the input ports I specify the dimensions: 2d, rows: 4, columns: 4. When I try to access the input port using f[x][y], it gives an error: “error C2109: subscript requires array or pointer type”, for the lines where the input port is adressed.

How can I create an s-function in Simulink with an input port that is a 2d array?

Relevant code:

static void mdlInitializeSizes(SimStruct *S)
{
  DECL_AND_INIT_DIMSINFO(inputDimsInfo);
  DECL_AND_INIT_DIMSINFO(outputDimsInfo);
  ssSetNumSFcnParams(S, NPARAMS);
  if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
  return; /* Parameter mismatch will be reported by Simulink */
  }

  ssSetNumContStates(S, NUM_CONT_STATES);
  ssSetNumDiscStates(S, NUM_DISC_STATES);

  if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
  /*Input Port 0 */
  inputDimsInfo.width = INPUT_0_WIDTH;
  ssSetInputPortDimensionInfo(S, 0, &inputDimsInfo);
  ssSetInputPortMatrixDimensions( S ,0, INPUT_0_WIDTH, INPUT_DIMS_0_COL);
  ssSetInputPortFrameData(S, 0, IN_0_FRAME_BASED);
  ssSetInputPortDataType(S, 0, SS_DOUBLE);
  ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX);
  ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
  ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

  if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;

  ssSetNumSampleTimes(S, 1);
  ssSetNumRWork(S, 0);
  ssSetNumIWork(S, 0);
  ssSetNumPWork(S, 0);
  ssSetNumModes(S, 0);
  ssSetNumNonsampledZCs(S, 0);

  /* Take care when specifying exception free code – see sfuntmpl_doc.c */
  ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
  SS_OPTION_USE_TLC_WITH_ACCELERATOR |
  SS_OPTION_WORKS_WITH_CODE_REUSE));
}

In mdlOuputs I try to treat f(the port) as a normal array.
Example:

x=f[0][0];

This throws the error.

Edit:
Well, sort of figured it out.

You set the port dimensions according to the input parameters, then you can address the values using f[x*xw+y], where x and y are the x and y positions(starting with 0) and xw is the number of columns.

Haven’t found a better way yet, but this works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:48:40+00:00Added an answer on June 7, 2026 at 11:48 pm

    I’m guessing that the S-Function builder is generating code that looks like the following in mdlOutputs:

    real_T *y0 = (real_T *)ssGetOutputPortSignal(S, 0);
    // OR 
    real_T *y0 = ssGetOutputPortRealSignal(S, 0);
    

    With either line y0 is a pointer to a 1-D array, so when you try to access it using 2 subscripts as if it were a 2-D array, the compiler complains.

    You can fix it by changing the 2-D indexing to linear indexing as you’ve posted in the edit. This works perfectly fine, in-fact it is what the compiler would have to do behind the scenes anyway when you index into a 2-D array using 2 subscripts.

    The other option is to cast the return value of ssGetInputPortSignal (or ssGetInputPortRealSignal) to a pointer to pointer type.

    real_T **y0 = (real_T **)ssGetOutputPortSignal(S, 0);
    
    y0[1][1] = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a function that will loop through an array of various
I am trying to create a function that will block access to some of
I'm trying to create a function that would dynamically allocate an array, sets the
I'm trying to create a function that will simply allow me to pass an
I am trying to create a function that will toggle between a play and
I am trying to create a function that will change the color of a
I'm trying to create a function that will check to make sure all the
I am trying to create a function that will split a string into search
I'm trying to create function that will do this same thing for 3 different
Im trying to create a function, that will return a mysql query, which i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.