Simulink fixed-step size protected variable name

Hi,
Is there any protected variable name for the Fixed-step size solver property pane that can be used in a block?
For instance, if I specify a number, let's say 0.001, I would like to use the variable name that points to the value in the configuration parameter. I know that a user specify a variable name and call it from workspace, but that is not practical in my model.
Thanks

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 5월 13일
편집: Fangjun Jiang 2022년 5월 13일

0 개 추천

If you set the fixed step size to be a particular value, you can get the value using the following command
get_param('ModelName',''FixedStep')

댓글 수: 6

That would give me the answer as a variable in the workspace.
If I want to set a gain with this command, it will not work. Maybe I wasn't clear. For instance I want a command to put on a gain (or whatever other block, like a constant) and have it self contained in simulink.
Thanks!
Not clear what is "have it self contained in simulink".
set the "Gain" value: set_param('PathToTheBlock','Gain','1.1')
to add Gain or other bloc: add_block()
You're giving me the commands to set the gain via a matlab script. What I need is some sorte of protected variable name that contains the time step value.
For instance, if I have a variable in the workspace called "sampletime" I can then open the model configurator and set the fixed timestep to "sampletime" e use this variable in the simulink block. If the model has a value configured as the fixed timestep value, then it should be an internal variable that I can assign to the block without needing to rely on any script/workspace variable.
Let's clarify. If the fixed time step of your model is set as "0.1" (it is a numeric value, not a variable name. The value could be "0.2", "0.3", etc.). You want this value to be used by a block in the model. Or, in other words, you want the "sample time" parameter of a block to be always the same as the "fixed time step" value of the model, no matter what that value is.
Augusto Dufloth
Augusto Dufloth 2022년 5월 18일
편집: Augusto Dufloth 2022년 5월 18일
That is correct, without using matlab script or workspace variable.
What would be your desired "imaginary" approach then? There is no such a term as a "protected variable name" in MATLAB/Simulink. I think you are probably thinking of a "macro" that can be linked to the fixed step size value and then it can be used anywhere else. But the answer is no.
The workspace variable approach is the best. Create such a variable, as if that is your desired "protected variable name".
There is another way to make it happen. That is to put two lines of command in the "InitFcn" callback of the model or block. Every time before the simulation starts, these two commands are executed, which is to get_param() the fixed step size value and then set_param() the block parameter.
These two commands are MATLAB scripts. But once they are set up, you don't have to type and run them in Command Line.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 5월 18일
편집: Walter Roberson 2022년 5월 18일

0 개 추천

"Is there any protected variable name for the Fixed-step size solver property pane that can be used in a block?"
No, there is not.
Would using a Datastore be acceptable for your purposes? That is, use the datastore variable to configure the solver step size, and then the same value would be available for reading anywhere else.
I do not know what would happen if you were to change the variable value during execution, especially without using set_param.
You talk about MATLAB scripts in a way that suggests to me that you are thinking of having a MATLAB script that sets the value and then calls sim(). But as you are not being specific on the wording you are also ruling out using a MATLAB Function Block that uses get_param and lets the result be a signal.
Now that I think of it... You could perhaps create a Constant block with an InitFcn callback that used get_param to fetch the step size and set the constant value; then feed the constant to wherever needed. That would be self-contained.

댓글 수: 1

I don't see a way that a Datastore can be used to achieve it.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 5월 12일

댓글:

2022년 5월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by