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!

답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 30일

0 개 추천

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

Robbe
Robbe 2011년 11월 30일
but doesn't that mean you create 11 different outputs? How do I put them in one vector?
Walter Roberson
Walter Roberson 2011년 11월 30일
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 2011년 12월 1일
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 2011년 12월 1일
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?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2011년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by