Passing array from S-Function to Matlab Embedded Function

1 view (last 30 days)
Hi all,
In Simulink, I am having a bit of a problem getting my array from one block to the next. I am currently generating an array of five values in an S-Function block and then trying to pass those 5 values over to a Matlab Embedded Function block to generate one output. So for example, the code in my .tlc file would look something like this:
*%<y0> = sarray;
and the function in the matlab block would look something like this:
function output = getOutput(marray)
output = marray(3) + marray(4);
Of course this isn't exactly what I'm doing, but the format is the same. Is this correct syntax for what I desire to do? Despite my best efforts, I cannot seem to get the output to come out correctly.
Any and all help would be greatly appreciated!
  1 Comment
Kaustubha Govind
Kaustubha Govind on 15 Jun 2011
I think it might be useful if you could provide a little more detail here:
1) Please show how you configure your output port and assign output values in your S-function code (TLC is used for code-generation only, and our immediate concern is simulation, which is governed by the S-function itself)
2) When you say that you can't get the output to come out correctly, please describe the symptoms - is there an error? If not, is it the output of the S-function or the MATLAB block that is incorrect. Also, please elaborate on how it is incorrect.
Typically, it is advisable to pre-allocate outputs in Embedded MATLAB to pre-define the output dimensions and type. For example, in your case:
function output = getOutput(marray)
output = 0; %output is a scalar
output = marray(3) + marray(4);

Sign in to comment.

Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!