Programmatically change user defined Library objects in Simulink model

I have made a plain Simulink model consisting of Current Sensor/Scope/Switch etc. There are also two subsystems (Load and Battery) that are user defined Library objects. Links looks fine. The model works and simulation results are correct.

Now I want to programmatically (from Matlab command window) change the Library objects. Say from Load_RLC to Load_R. Both exists as Library objects. I have tried commandos like:

open_system(‘LowVoltageSystem’)

add_block(‘Load_R’,’LowVoltageSystem’)

pos=get_param(‘Load_RLC/LowVoltageSystem,’position’)

delete_block(‘Load_RLC/LowVoltageSystem’)

set_param(‘Load_R’,’position’,pos)

But the ‘Load_R’ can not be found (There is no block named ‘Load_R’)

I have also tried things like:

replace_block(‘LowVoltageSystem,’Load_RLC’,’Load_R’)

Here the ‘Load_R’ is invalid block type.(Invalid NewBlock (<Load_R>) passed to REPLACE_BLOCK. Try built-in/BLOCKTYPE or a valid block name.)

The replace_block command, however, works with the built-in library blocks.

If I change the library components ‘manually’ everythings works, so there is nothing wrong with the components themselves.

What am I doing wrong here?

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.

In the first part of your code, add_block() is not used properly. You need to specify the full path of both the source and destination blocks. Look at examples in “doc add_block”.

replace_block() is the ideal function to use for your task. Again, you need to specify the full path of the source and desination blocks, e.g. ‘CustomLibraryFile/LibraryBlock’, ‘ModelFile/ModelSystem/BlockName’. For custom library, you also need to open the library first using open_system() or load_system()

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.