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

Executing a MATLAB script at the start of a Simulink run

641 views
Skip to first unread message

Steve Leschuk

unread,
Nov 3, 2004, 4:32:31 PM11/3/04
to
Here's my question:

Is there some way to execute a MATLAB function only once at the start
of a Simulink simulation and read in a 2D matrix generated by that
MATLAB function into a Lookup table block? The 2D matrix is not an
input signal or function of the simulation time.

------------------
The detailed explanation of the problem:

I'm currently moving a large MATLAB simulation over to simulink.

One particular function in the simulation is only called at the
beginning of the simulation and outputs a 2D matrix of real elements.
These elements are accessed, but not changed at various times in the
simulation. A sizeable portion of this function generating the
script resides in a for loop which typically loops 500 times. Each
loop outputs a single 3X1 vector. The 3x1 vector output of one loop
is entirely dependent on the previous 3X1 vector. The total matrix
output will be 3X500.

I'm trying to determine the most efficient way to put this function
into Simulink. I've considered the following:

(1) Direct Block Realization - To calculate the 3X500 matrix at time
0 would required a huge number of blocks.
(2) M File S-Function (level 1)
(3) Embedded Matlab Function

For (2) and (3), I am concerned about longer simulation times. I
also want to make sure that the 3x500 matrix is only generated once.
I don't want my simulation wasting time regenerating the value at
every discrete interval.

Is there some way to execute a MATLAB function once at the start of a
Simulink simulation and read in a 2D matrix value into a Lookup table
block?

Thomas

unread,
Nov 4, 2004, 9:05:32 AM11/4/04
to
1. Open your model with an editor
2. Look after 'PreLoadFcn'
3. behind this insert your .m-file

There is a way to do this directly in simulink, but in the moment I'm
not sure where to find...
But the first way has to work!

Hope this helps

Amanda Galtman

unread,
Nov 4, 2004, 9:15:15 AM11/4/04
to

"Steve Leschuk" <xxsxlxesx...@yahoo.com> wrote in message news:eeeff...@webx.raydaftYaTP...

> Here's my question:
>
> Is there some way to execute a MATLAB function only once at the start
> of a Simulink simulation and read in a 2D matrix generated by that
> MATLAB function into a Lookup table block? The 2D matrix is not an
> input signal or function of the simulation time.

Hi Steve,

Check out the doc about model callback functions:

http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/creating_model41.html#56417

http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/ug/creating_model47.html#132871

HTH,
Amanda

Steve Leschuk

unread,
Nov 12, 2004, 11:00:16 AM11/12/04
to
Thanks! It worked
0 new messages