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

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

From: Jean-Baptiste

Date: 5 Dec, 2011 14:47:09

Message: 1 of 5

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

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

From: Phil Goddard

Date: 7 Dec, 2011 09:47:08

Message: 2 of 5

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.

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

From: Jean-Baptiste

Date: 4 Jan, 2012 11:26:08

Message: 3 of 5

"Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in message <jbncms$nr6$1@newscl01ah.mathworks.com>...
> 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.

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

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

From: Jean-Baptiste

Date: 4 Jan, 2012 11:27:08

Message: 4 of 5

"Phil Goddard" <phil@modeling-simulation-visualization.com> wrote in message <jbncms$nr6$1@newscl01ah.mathworks.com>...
> 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.

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

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

From: Phil Goddard

Date: 5 Jan, 2012 00:22:08

Message: 5 of 5


> 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.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sfunction work ... Jean-Baptiste 4 Jan, 2012 06:29:09
real time simul... Jean-Baptiste 4 Jan, 2012 06:29:09
cmex sfunction Jean-Baptiste 4 Jan, 2012 06:29:09
dynamic vector Jean-Baptiste 5 Dec, 2011 09:49:12
simple average Jean-Baptiste 5 Dec, 2011 09:49:12
simulink Jean-Baptiste 5 Dec, 2011 09:49:12
sfuntion Jean-Baptiste 5 Dec, 2011 09:49:12
wma Jean-Baptiste 5 Dec, 2011 09:49:12
rssFeed for this Thread

Contact us at files@mathworks.com