Reverting Referenced Subsystems back to normal Subsystems

Hi,

I use MATLAB/Simulink R2019b and its new feature: Subsystems Reference.

During develpoment I use referenced subsystems since they are used in multiple models.

Before the models are distributed to customers, the referenced subsystems must be reverted back to ‘normal’ subsystems for various reasons.

Since MathWorks does not provide a feature for this behavior I wrote some code in order to do it. In this code I use the ‘expand subsystem’ feature to break the referenced subsystem links.

Now I have to change my MATLAB/Simulink version to R2020a and suddenly the expand subsystem feature no longer works for referenced subsystems. This change is not documented in the release notes or anywhere else.

Has anyone an idea how I can change my referenced subsystems back to ‘normal’ subsystems without copying the whole content from one subsystem into antoher one?

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

I can confirm that the feature to expand referenced subsystems was removed in R2020a. So, it looks like the best way around is to copy the referenced subsystem to all locations. This can be done using the simulink.blockdiagram.copycontentstosubsystem command. I suppose replace_block will be useful along with it but I haven’t tried it out.

I’ve written a script to demonstrate how you could go about this. I’ve used add_line and delete_line instead to reconnect the subsystems.

And here’s the script that does that:

refSubsystem = 'subsys20b';
modelName = 'modelRefSubsys20b';
open_system(modelName);
oldBlock = [ modelName '/Subsystem Reference'];
newBlock = [ modelName '/subsystem'];
% create a copy of the referenced subsystem
add_block('built-in/Subsystem', newBlock)
Simulink.BlockDiagram.copyContentsToSubsystem(refSubsystem, newBlock)
% Retrieve useful info from the old block
t1 = get_param(oldBlock, 'Portconnectivity');
t2 = get_param(oldBlock, 'PortHandles');
t3 = get_param(newBlock, 'PortHandles');

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.