Plant box in Simulink - matlab

I am looking for a box in simulink that is "plant".
I cannot seem to find it in the search option of simulink.
Like the one in the next pic:

That's a subsystem that the person who created the model made, it's not a standard Simulink block. You need to look inside the subsystem to see how it's constructed. See Create a Subsystem in the documentation for more details.

Related

Simulink: replace existing subsystem with another one

How do i replace an existing SubSystem in a given model with another SubSystem from another model.
I tried commands like:
Simulink.SubSystem.copyContentsToBlockDiagram(subsys, bdiag)
replace_block
but nothing worked (maybe I used it wrong).
Remarks:
I am using matlab 2011b.

Simulink find() does not follow resolved links

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).

Variable subsystem implementation in Simulink 2007a

I've seen that it's already implemented in Matlab R2013 in the form of Variant Subsystems, but budget and convenience don't show the upgrade necessary yet:
I am seeking a subsystem in which a concrete implementation can be selected prior to running the simulation, in Matlab R2007a.
A bunch of enabled subsystems along with a switch block connected to a masked variable would do the trick, however the whole family of selectable implementations must coexist inside the "container" subsystem.
Any workaround, other than upgrading to R2013?
Thank you.
I have come up with the following workaround.
1- Include all the possible implementations in a Library
2- Create a Configurable Subsystem block in the Library and edit it to include all the desired implementations
3- Right clicking in a Configurable Subsystem instance will show the "Block Choice" option where the desired implementation can be chosen.
Regardless of differences that may exist with respect to the Variant Subsystem solution when it comes to code generation, RT targets etc..., this solution works for me.

In simulink, programmatically create a variant subsystem

I want to use scripting to create and define a variant subsystem in simulink.
I am able to create the variant subsystem and add subsystems within it using the add_block but cannot find the appropriate property that defines the variant subsystem by using the get_param command.
The way I graphically configure a variant subsystem is by right clicking the block and going to Block Parameters and then adding the variant control conditions for each subsystem.
I want to do the same thing but from an m-file so that I can create multiple blocks programmatically.
I checked the documentation and google search but couldn't find anything.
Thanks in advance.
Based on a comment by #Praetorian, I opened the model in a text editor and found the parameter line where the variant condition was defined.
I found that the variant conditions are stored in the subsystems within the variant subsystem and not within the top-level variant subsystem.
So you store the condition within each subsystem's "VariantControl" parameter.
Example:
set_param([variantSys '/' sys],'VariantControl','a==1') where sys is a subsystem within the variant subsystem variantSys.
The variant control should be written on the Callbacks of the Model. In order to put the simulink variant controls available to the model, the variables should be created in the workspace. For this to happen you need to put your Sys = Simulink.Variant(Mode== value) etc on the PreLoadFcn.
Check access PreLoadFcn and put the formulas in there then your table will be automatically filled.
If you do not mind can you tell me how you created the variant subsystem?
Good luck

Is it possible to call specific functions before a Simulink simulation begins?

More specifically, I would like to automatically clear the workspace and all functions before a Simulink simulation starts. Is this possible? Are there hooks where I can define functions to be called before and, say, after each simulation?
You can do this using model callbacks.
You can set callbacks programmatically as described on the linked page, or just right-click on an empty spot in your model file, select Model Properties, then the Callbacks tab and enter the name of the function to be called after selecting the appropriate callback in the left pane.
In your case, the StartFcn callback seems appropriate.