
How do I access simulation end time of Simulink model from within a MATLAB function block?
12 views (last 30 days)
Show older comments
I'm writing a MATLAB function block which would like to know how long the simulation it contains is to be run. I.e. I would like to set a variable in my MATLAB function block to be equal to whatever number the user chose as simulation end time (10 by default).
I would guess / hope that this is a simply accessible property of some object or another, but I cannot seem to find out what is it called or where to read it off.
Ideally I would like to include this block in a library to be used in different models, so it shouldn't need to have any prior information about the model it is used in.
0 Comments
Accepted Answer
Sebastian Castro
on 8 Oct 2015
I think the easiest thing to do is define a variable in MATLAB base workspace -- let's call it tEnd.
Then, set your simulation end time to tEnd. On the other hand, add the variable tEnd to your MATLAB Function block as a parameter, as shown in this page.

- Sebastian
More Answers (1)
Albert Ziegler
on 13 Oct 2015
4 Comments
Christopher Yi
on 27 Apr 2020
I also have the same problem, what code is that, matlab or C? cuz I put it in the Matlab function block but arose error 'Function 'get_param' not supported for code generation.'
em
on 6 Jun 2022
Assuming you don't actually need to use this function for code generation (perhaps just for testing), you can bypass the code generation for that function using "coder.extrinsic('get_param');"
See Also
Categories
Find more on Event Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!