Access to "hidden" variables in Simulink - matlab

Some example models that are included in the Simulink library, include some variables that their value is not visible. For instance, in the model power_PVarray_grid_det the sample time of the powergui is defined as Ts_Power. I can not figure out the value of this variable. Is there a way to find these hidden variables, have access to them and change their value?
Thanks in advance

Related

modify model's parameters in dymola's script file

I am trying to use a .mos file in Dymola to do multiple simulations, here is an example from claytex's blog:
openModel("C:/Dymola/Testing/Test1.mo")
translateModel ("Test1");
for i in 1:10 loop
a=i;
simulate();
system("copy dsres.mat results"+String(i) +".mat");
end for;
It seems when I translate a model in the script file, I could modify the model's parameters again, which is different when I use Dymola's GUI. In Dymola's GUI, if I try to modify the parameter after I translate the model, I have to re-translate the model. My question is:
In Dymola's script file, when I modify the parameter, how does Dymola deal with it?
The above comment by "user2024223" is correct, but I think "variable browser" is not stressed enough and some more explanation could help:
When changing the model's parameters after translation, make sure you are not using the model editing (either "Graphical" or "Text"-Ribbon), because this will change the model's code and therefore (usually) force re-translation. The same is true for the "Model View" in the "Simulation" Ribbon.
The code will not be changed if you use the "Variable Browser" in the "Simulation"-Ribbon. An alternative (which actually does the same) is typing the parameter value in the "Commands"-line. E.g. this could be J1.J=5 for the CoupledClutches example. Both of the variants in the paragraph should behave similarly to the script.
Dymola deals with parameter changes after translation by modifying the dsin.txt file.
Some/many parameters have been evaluated and cannot be changed in this way - these variables are not editable in the Variable Browser.
You will get a warning if you try to change non-editable variables in a script.
Note: You should in most cases not have to deal with re-translating the model even after modifying the editable parameters of that model in the GUI. Just simulate the model again - hopefully it does not need re-translation.

How do I define variables in simulink model (instead of in workspace)?

I want to define a few variables in a simulink model. The matlab function block doesn't work because the variables are local. The variables are not input to other blocks, but instead, the variables are parameters to other blocks.
Basically, I want to have a block where I can define a bunch of variables that set the parameters for other blocks. I did this once in the past more than a few years ago now, but I can't find or remember how to do it.
I thought I used a block, but potentially, I set the variables somewhere in model settings or something. I can't remember, and I am not having luck finding it. Any help is much appreciated! I feel this is simple, but I just can't find the solution.
You can do this by defining your data in the model's "Model Workspace", like this:
. There's more about the Model Workspace in the doc. There are various options as to where you can store the parameters.
You can use Simulink data dictionary or model workspace to store the variables/Parameters. go through this link to get more info Usage of the variables/Parameters/Signals for simulink models

How to import a header file to load constant values in Simulink? (for generable code)

I'm developing a Simulink model with many constants.
I'm trying to:
Avoid hardcoding every constant in the model and have something unreadable.
Be able to know what that 9.73288483... constant in the middle of my model stands for.
I wanted to add all my constants to a header file to have them as global constants (/including the header file everywhere) so that I could directly refer to their name instead of the value and it would also simplify my model.
Another reason for me to use a header file is that I will then generate my model in C using Simulink coder, and I really want to have that header file to have a clean generated code
I've seen people in here referring to the existence of such function.
So I've been wondering if anyone here could help me out?
Then I could also apply it to replace my functions parameters by global constants in another header file which would let me simply load a different "parameters_values.h" file when I want to change the conditions of my simulation easily.
You can specify under "file->model properties" callback functions

Control Variables in SIMULINk

I'm new to Matlab and SIMULINK, and I know that this might be easy. But I just can't find the answer on the internet.
I'm building a SIMULINK model (group of blocks) and I want to set the values inside the blocks as variables so I can maybe control it from an m file or something. How can I do this?
As #rayryeng has pointed out you can just type the name of a variable in place of the parameter value of blocks, and then whatever value that variable is set to in your Matlab workspace will be used.
Whenever I do this, I like to set default values of the variables in the models intialization callback function details here. That way your model is portable and will run on it's own.
In the simulink model,
In the 'Value' field of a Constant Block, enter the variable name. The constant block will then look like this: (see uplim and lowlim)
Now, whenever you wish to change the variable's value, execute the following commands through an m-file:
Let's assume the variable's name is pressure and the new value is 5.
assignin('base','pressure',5);
set_param('path of constant block','Value','pressure');
The path to a constant block (or any simulink block) looks something like this: modelname/Constant2 (considering it is the top level of your model; Constant Block number can vary)

Impossible to tune Simulink Parameter at simulation time

I have a problem. I have an embedded function in my simulink model which has a structure (struct) as parameter. It contains only numerical values and I generate an S-Function of the embedded function by right clicking on the block and C/C++ code --> Generate S-function.
I then have the compiled block, if I try to change some values of my struct nothing changes (the fields of my struct stay the same as when I first compiled my embedded function).
When I compiled the embedded function block I selected the parameter to be tunable. I selected the parameter to be tunable in the Model Explorer. I tried to follow this video tutorial by mathworks: http://fr.mathworks.com/videos/tunable-structure-parameters-68947.html (The video is for r2010a while I am at r2015b) It is a bit different the interface in r2015b (from the one in the video) but when I click on Configure , like the guy does in the video, nothing happens.
Could you help me please?
Thanks a lot.
Once I had also decided to reduce the number of tunable parameters by checking the 'inline parameters' checkbox and then specifying the exception variables (variable that have the permission to be tunable even when 'inline parameters' is turned on. It did not work.
In case you aim does not heavily rely on optimization, it would be better if you simply turn off 'inline parameters'.
After that, the constant blocks (i suppose you are giving the input to your s-function from constant blocks) will become tunable.
Another advice: add mex in the init function of your model callbacks. It will save you from getting weird output (usually due to uncleared/un-reset variables from previous runs).
Hope it helps!