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

How to define a dynamic vector in simulink's S-function

105 views
Skip to first unread message

Jean-Baptiste

unread,
Dec 5, 2011, 9:47:09 AM12/5/11
to
Hi,

I need to be able to determine the mean value average of certain outputs that i'm obtaining with Simulink S-function blocks. In simulink library there's the WMA block that allows me to determine these averages (weighted averages). The problem in my case is that, the number of points per cycle is changing constantly, so the WMA block is useless.

i know the algorithm of this moving average block already, and i'm intending to insert it manually in my code via an S-function. The problem is: i need to insert the values that need to be averaged in a certain vector in a way to use my algorithm.

Can you help me please regarding the definition of a certain parameter in Simulink S-function which is not a constant, but a dynamic vector. Then i'll introduce a constant index that allows me to manipulate the different values of this vector ( for the Mean Average Algorithm)

Best regards,
JB

Phil Goddard

unread,
Dec 7, 2011, 4:47:08 AM12/7/11
to
You need to use dynamically sized signals.

But if your code to perform the average doesn't have memory (i.e. it doesn't need to remember the signal values from one time step to the next) which it doesn't sound as it it does, then you may be better using an embedded MATLAB Function block.

How to create dynamically sized signals in EML blocks is well documented.

Phil.

Jean-Baptiste

unread,
Jan 4, 2012, 6:26:08 AM1/4/12
to
"Phil Goddard" <ph...@modeling-simulation-visualization.com> wrote in message <jbncms$nr6$1...@newscl01ah.mathworks.com>...
Hello Phil,

regarding the dynamically sized signal: do you mean the Work vectors defined in a S-function code?

second, if we need to remember the signal values from one step to another: yes we do so.

and finally regarding the use of an embedded function in our model: we're working in real time simulation, so an embedded function can't be used in our model (a model involving Embeded MATLAB function will result in a high calculation time, which is not ideal for real-time simulation.), that's why it is all coded using the C-mex S-function from the first place.

Any other ideas or solutions would you like to share with us?

Best Regards,

JB

Jean-Baptiste

unread,
Jan 4, 2012, 6:27:08 AM1/4/12
to
"Phil Goddard" <ph...@modeling-simulation-visualization.com> wrote in message <jbncms$nr6$1...@newscl01ah.mathworks.com>...

Phil Goddard

unread,
Jan 4, 2012, 7:22:08 PM1/4/12
to

> regarding the dynamically sized signal: do you mean the Work vectors defined in a S-function code?

No.
I mean variable sized signals as per the examples at
http://www.mathworks.com/help/toolbox/simulink/ug/br9ecac-1.html

Although if over head is an issue in your rtos then I suspect you don't want to use variable sized signals, but rather need to determine an appropriate size in advance and make all signals have that length.

Phil.
0 new messages