How to set fixed values to Simulink parameters instead of variable?

Maybe there is an easy solution to this but i dont konw how to do it.
Lets say for example i do have a variable "a" with the value "2" in matlab and i want to set a gain block parameter to the value of "a" which is 2. Naturally i would write "a" into the parameter. If i do now save the Simulink model and use it later, it always requires a variable "a" in the Matlab Workspace. But i dont want it to be linked to the variable but instead to be actually the value of that variable.
Hope this is understandable.
This is just boiled down to an easy example.
I am searching for something like: set_param([...],'value',valueof(a))
Alternatively: instead of setting the fixed values to the simulink block parameters, is it posiible to save all necessary variables with the Simulink model?
Thanks.

 Accepted Answer

Not following your point. If you want the gain to be a, put in a. If you want the gain to be 2, put in 2.
You can add 'a' to the "Model Workspace", not the "Base Workspace". It will be saved with the model.
Open the "Model Explorer" (Ctrl+H), on the left panel, expand the root level model to see "Model Workspace"

3 Comments

Thanks. Guess i do have to be more specific. I do have a matlab script creating a new simulink model. During the creation via the matlab script various parameters of Simulink blocks are getting filled with i.e. matrices. I am now searching for a way to set those parameters to their actual value. So instead of setting them to 'matrix_a', setting them to '[0,1,2;3,4,5;6,7,8]' the content of 'matrix_a'.
Currently I am doing this:
set_param('Constantblock_name','value','matirx_a');
But I am searching for something like this:
set_param('Constantblock_name','value',valueof(matirx_a));
that is doing this:
set_param('Constantblock_name','value','[0,1,2;3,4,5;6,7,8]');
Yes. Most block parameters need to be provided in the string format, not the numerical format.
You can use num2str(), mat2str(), int2str() for this purpose.
Thank you very much mat2str() is what i was searching for.

Sign in to comment.

More Answers (0)

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!