I'm using a Stateflow chart to generate some code (C action language). I would like to declare a subchart variable as persistent (or static), so the value is remembered the next time the subchart is executed.
A solution is to attach this variable to one of the parent states, but then this variable is visible to all the subcharts, which is not ideal.
Another solution is to create an embedded Matlab function with persistent variables on it, but this is too cumbersome, since I would need to read all the variables in the beginning and write them before leaving the state.
Is there a simpler way to achieve this?
Yes. Open Model Explorer, go to the subchart, add data.
Related
Short of printing a variable in a new cell, I don't know a good fast method to view a specific variable in jupyter.
I am aware of the Variable Inspector nbextension; but that shows ALL variables rather than a specific one.
Is there some way to do this which I'm missing?
A while ago I was reviewing some legacy code, and I incurred in the following issue: the developer create many variables starting with a dot (like .variable1), syntax reserved to define namesspaces.
When quizzed about the use of that convention, he replied that essentially that was a way to create global variable within the scope of a function - what in Python you would achieve doing the following:
def define():
global a
a = 2
define()
print(a)
In q, that translated in something like this:
f1:{.b1:2;}
f2:{b1:2;}
f1[] / this creates a variable .b1, which you can use globally
f2[] / this creates a variable b1 within the scope of the function, not usable outside
While my preference would have been to create a global variable using a namespace (something like f1:{.my_namespace.b1:2;}), the code was doing its job without any issues.
The problem arises if I want to delete the global variable defined which starts with a dot (.b1 in the case just described), given that approaches like
delete .b1 from `.
do not seem to work. All the references I was able to find (like this) suggest that namespaces cannot be delete, which would imply these unproperly defined variable will stay there.
To be clear, the problem is not about how to delete variables from namespaces, but to delete those namespaces which are used as variables - if possible at all.
Any ideas?
Based on your question, you want to delete variables from a namespace. You can do this by running:
delete b1 from `.my_namespace
Which is also explained in the link you pasted.
What you can't do is actually delete the reference to my_namespace.
As a side note you can also set variables globally in the root namespace using the set keyword:
{`var set 2}[]
Which will let you avoid having to create single use namespaces.
How do I create variables inside of a macro? I've created a macro library with some macros and now I am trying to figure out how to create a local variable that exists inside a macro for the lifetime of the macro. Perhaps theres a way to store that data somewhere else?
While editing the Macro, use the Inputs collection of the Details panel to create a dummy variable of the required type.
Do not check the By-Ref checkbox.
Leave it unconnected when calling the Macro.
Use the variable like any other variable.
If you are not using latent functions like delay or timeline, use functions instead.
I create function libraries anytime I need code reuse.
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
I want to do something like this: a program where at the beginning some data is initialized. Then I open other GUIs where I show some graphics from these data.
Is there any possible way to set some global variables for different GUIs? If not, how could I do it?
As long as you pass the handle of the first GUI to the second, you can access all the properties of GUI#1 from GUI#2 (and vice versa, since the GUI creation method returns the handle to GUI#2).
Alternatively, you can collect the data you want to visualize (as well as the handles of the GUIs) in a handle object, which means it is passed by reference and thus available everywhere.
Finally, you can, of course, create global variables - at the beginning of any function that would like to access these variables you have to declare them as global var1, var2, var3.