Matrix as output in an S-function

Hi, I'm trying to put a matrix in the output of an s-function but I'm getting following error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
I think because I'm writing a matrix where Matlab expects a constant...
I think this is the relevant code:
sizes.NumOutputs = NumberOfOutputs;
...
[sys,next_state] = updateFSM(x,u);
...
function [NumberOfInputs,NumberOfOutputs,InitialState]=initFSM()
NumberOfOutputs = 2;
...
function [Output,next_state]=updateFSM(state,Input)
CS = 1;
STROOM = zeros(1,10);
...
Output(1) = CS;
Output(2) = STROOM;
Is it possible to output a matrix (with a fixed dimension of 10 bits)?
My S-function is importing one bit each clock cycle and storing it in a matrix. After 10 clock cycles the resulting matrix should be exported.
Thanks in advance!

Antworten (1)

Walter Roberson
Walter Roberson am 30 Nov. 2011

0 Stimmen

Change
Output(2) = STROOM;
to
Output(2:11) = STROOM;
If you want CS and STROOM to be distinct from each other, then your routine has three outputs rather than the 2 your code claims.

4 Kommentare

Robbe
Robbe am 30 Nov. 2011
but doesn't that mean you create 11 different outputs? How do I put them in one vector?
Walter Roberson
Walter Roberson am 30 Nov. 2011
Your code appears to be at least partly in Level-1 S-Function form. You must decide between Level-1 or Level-2 as their calling protocols are quite different.
http://www.mathworks.com/help/toolbox/simulink/sfg/f7-67615.html#f7-59576
Kaustubha Govind
Kaustubha Govind am 1 Dez. 2011
Robbe: Walter's solution is a single vector which has 11 elements - the first element is CS and the remaining 10 elements comes from STROOM.
Robbe
Robbe am 1 Dez. 2011
We have to use a template of a Level-1 function
Is it possible to have 11 outputs and then put 10 of them in one vector afterwards?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 30 Nov. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by