How to access Fundamental Sample Time value within a simulink model

I have a model will run fixed step discrete. Some of the subsystems I must use require the value of the fundamental step time as an input.
The quick version is, of course, to use a constant as an input and set it equal to the value of the fundamental sample time that's input in the configuration parameters.
And, of course, this method is an invitation to subtle bugs when the configuration parameter is changed but someone forgets to change one of the constant blocks to match.
So - is there a way to simply pull in the value that's been set within the configuration parameters?
Thanks.

 Akzeptierte Antwort

Vishal Rane
Vishal Rane am 28 Nov. 2012
Bearbeitet: Vishal Rane am 28 Nov. 2012
SampleTime = get_param(MdlName,'FixedStep')
gives you the Fixed-step size (fundamental sample time) as specified in Simulation > Configuration Parameters.
You could also use this inside a model callback (startfcn) to ensure that value is present in the base when the model is simulated.
Refer Link for more information.

4 Kommentare

Hello!
I have a custom library with blocks. In one block I want to use the fundamental sample time of the model in the mask editor of the block. Like you mentioned above it is necessary to use the name of the model "MdlName" in the function get_param(). I want to use the block of my costum library in different models with different model names. How should I implement the function get_param() to avoid changes in my mask editor everytime I insert the mentioned block of my library in a new model?
Thanks for your help!
get_param(bdroot, 'FixedStep')
This doesn't seem to work for Stateflow. I am trying to access the Stateflow chart's discrete Sample Time for part of a state's during: section. Any way I can do this?
Hi Dana!
I am having the same issue as you, could you find a way to do what you are asking here?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Babak
Babak am 27 Nov. 2012

1 Stimme

In Simulink Library Browser, go to the Simulink, Signal Attributes, section. There is a block called Weighted Sample Time.
That's what you can use to multiply any signal with it to get Ts.

2 Kommentare

Not quite what I need - the block wants a constant input equal to "dt" -- but I suppose I can fake this by using the weighted sample time with a unit input.
Just surprised there isn't a way to access this as an "environment-ish" variable.
Simulink is based on blocks and signals. I don't think there is any pre-defined, and system set up variable like Ts that you can just simply write it anywhere in any block and use it that way. I think the only solution is what you said, just connecting a unit step or 1 constant source to the Weighted sample block.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Schedule Model Components finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 27 Nov. 2012

Kommentiert:

am 27 Mär. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by