Simulink find() does not follow resolved links - simulink

I have a Simulink model "mod" with a Subsystem "link" in it, which is actually an active (i.e. "resolved") library link. Inside this linked Subsystem there is a Stateflow Chart "chart".
In Simulink I can search for the Stateflow Chart like this:
find_system('mod', 'FollowLinks', 'on', 'Name', 'chart')
But when I have the model as object "modObj", I can also use its "find" method:
modObj.find('Name', 'chart')
Unfortunately the "find" method does not follow resolved library links by default. Also the documentation does not describe a parameter like "FollowLinks" for "find_system". I already tried using "FollowLinks" and "-followlinks" but without success. Also searches on the net gave no result.
Is there an undocumented parameter for this functionality?
I know that I can use the "find_system" function for the above example. But in fact I am searching for Stateflow objects inside models, which are only found by the "find" method.

It seems that it is not possible to navigate through linked Stateflow objects. I have now worked around this by implementing a method which detects linked Stateflow charts (by using the "ReferenceBlock" property of the Simulink handle), ensuring the linked library is loaded and returing the library's object. Then I am able to work on the library instead of the current model (although it might be locked, but searching and property extraction is always possible).

Related

How to programmatically configure the tunability of model parameters?

I'm porting a large Simulink model from Simulink R2010a → R2017b.
The main model is basically a glue-layer for many interwoven reference models. My objective is to generate a standalone executable out of this main model using Coder.
Parameter tunability in this context is not done via the Signals and Parameters section on the Optimization tab in the Model Configuration Parameters dialog (as is the case in stand-alone models), but rather, via constructing Simulink.Parameter objects in the base workspace, and referencing those in the respective referenced models, or in their respective model workspaces.
Now, AFAIK, in R2010a it was enough to set
new_parameter.RTWInfo.StorageClass = 'Auto';
new_parameter.RTWInfo.CustomStorageClass = 'Define';
to make the parameter non-tunable and convert it into a #define in the generated code. In R2017b, this is no longer allowed; the StorageClass must be 'Custom' if you set a non-empty CustomStorageClass:
new_parameter.CoderInfo.StorageClass = 'Custom'; % <- can't be 'Auto'
new_parameter.CoderInfo.CustomStorageClass = 'Define';
But apparently, this does not make the parameter non-tunable:
Warning: Parameter 'OutPortSampleTime' of '[...]/Rate Transition1' is non-tunable but refers to tunable variables (Simulation_compiletimeConstant (base workspace))
I can't find anything in the R2017b documentation on making parameters non-tunable, programatically; I can only find how to do it in stand-alone models via the dialog, but that's not what I want here.
Can anyone point me in the right direction?
NOTE: Back in the day, Simulink Coder was called Real-Time Workshop (well, Real-time Workshop split into Coder and several other things), hence the difference RTWInfo vs. CoderInfo. Note that RTWInfo still works in R2017b, but issues a warning and gets converted into Coderinfo automatically.
In generated code it should appear as #define, the way you specified it.
https://www.mathworks.com/help/rtw/ug/choose-a-built-in-storage-class-for-controlling-data-representation-in-the-generated-code.html
Btw, yes, it's a bit confusing, because in m-file you specify CustomStorageClass = 'Define';, in GUI you specify Storage class as Define (custom), but in documentation they say Storage Class as Defined.
I am not sure why warning about tunability shows up.

error when setting PostCodeGenCommand for a simulink model

I would like to add a post-build hook to my code generation process. However, when I try to associate a function with the simulink model's PostCodeGenCommand, I get the following error.
set_param(bdroot, 'PostCodeGenCommand', 'packNGo(buildInfo);')
A configuration set reference does not allow writing to parameters in the source configuration set
I don't really understand the error message, and it doesn't bring up any useful hits on my favourite search engine. Can anyone help me decipher it?
Unfortunately, I could not reproduce this problem on a simple simulink model, even if I included a reference model. (I thought that might be what the word "reference" was, um, referencing in the error message. And I've noticed previously that referenced models are handled differently to other models in the simulink code generator.)
I'm using R2015a, but have access to the newer versions if that would help.
Note that this question was originally posted on the Matlab forum, but didn't get any answers.
It turns out that the model was using a "configuration reference" rather than storing its configuration internally. The Model Explorer provides the following description
Configuration Reference
A model may reference a 'Configuration set' that is defined in the
source location rather than stored in the model....
This is useful for us because we use several models which all share the same configuration set. It's saved in a central place and all updates apply immediately to all models.
The side effect is that bdroot no longer has a PostCodeGenCommand associated with it. Instead, the command I was looking for was
configurationSettings.set_param('PostCodeGenCommand', 'packNGo(buildInfo);')
where configurationSettings is a variable in your workspace, and the variable's name should match the "Referenced configuration set name" in the Model Explorer.

Use command line to browse LinearModel object properties

I'm following the regression tutorial at http://www.mathworks.com/help/econ/estimate-regression-model-with-multiplicative-arima-errors.html. In particular, I am browsing the object Fit=fitlm(X,logY). I know I can double-click the object in the Workspace window, but I often don't want more windows. I might just want to list the members at the command line. According to http://www.mathworks.com/help/ident/ug/linear-model-structures.html#bq4gq_u-20, I should be able to do this with the get method. However, Matlab informs me that the Linear Model class doesn't have a get method [tried Fit.get, Fit.get(), and get(Fit)]. What am I missing?
As for browsing the properites using the GUI window, I'm finding that the Residuals property is not present. According to http://www.mathworks.com/help/stats/linearmodel-class.html, it should be present. Thanks for any light that can be shed on my misunderstanding of the class.
I've posted this at:
http://groups.google.com/forum/#!topic/comp.soft-sys.matlab/b0jHdrX6_ZY
You can list all the property names of an object using the properties function. In your case:
properties(Fit)

programmatically adding "matlab function" block to simuliink [duplicate]

In my Simulink model are some embedded MATLAB functions. Is there a way to get the content (the text you see in the editor) of this blocks?
My first guess was to use find_system to get the embedded MATLAB functions and then get_param to get the content. But I dont find the needed parameter name. The documentation didnt show up any parameter for the embedded MATLAB functions.
Try this technical solution on the Mathworks website.

How to get the content of an embedded MATLAB function

In my Simulink model are some embedded MATLAB functions. Is there a way to get the content (the text you see in the editor) of this blocks?
My first guess was to use find_system to get the embedded MATLAB functions and then get_param to get the content. But I dont find the needed parameter name. The documentation didnt show up any parameter for the embedded MATLAB functions.
Try this technical solution on the Mathworks website.