Forget all known references or find all potentially broken references
2 views (last 30 days)
Show older comments
I run scripts over multiple models, where the models get loaded in various orders. Assume in model1 there is a reference, that gets resolved, if I load model2 before model1 (get_param(block, 'ReferenceBlock') == 'qlib/...'). If (after a clean start of Matlab) I open only model1 however, the references is broken (get_param(block, 'ReferenceBlock') == 0x0 empty char array).
Is there a way to either:
1: Clear the cache of known references? I tried clear all, bdclose all; close_system; Simulink.LibraryDictionary.clear; Simulink.LibraryDictionary.resetLibraryLinks to no avail. Apparently MATLAB keeps track of known references somewhere else. The only way, I managed was to restart MATLAB.
2. Find out if a Reference is not self-contained, even if currently resolved, i.e. broken without loading some other model? I did not find a good get_param property for this.
0 Comments
Accepted Answer
Devon
on 10 Nov 2023
Question 1:
MATLAB has a rehash function that can reset the cache. https://www.mathworks.com/help/matlab/ref/rehash.html
rehash toolboxcache
Question 2:
This might be what you are looking for. https://www.mathworks.com/help/simulink/slref/find_mdlrefs.html
find_mdlerefs('modelName')
This will find referenced models and Model blocks for all models referenced by the specified model. It will provide an error when a link is broken.
3 Comments
Devon
on 13 Nov 2023
Ahhh! Those are library links, not model refs so the above wouldn't error out. Here are some resources on library blocks and their links.
Part 1:
I think this first link is what you are looking for. Look at the section for "link status":
You can also take a look at the following link to find some other ways to check info on library blocks (and other simulink blocks in general): https://www.mathworks.com/help/simulink/slref/find_system.html
- Blocks linked from libraries have a parameter called "ReferenceBlock" which indicates the library and block that this block is linked to.
- When a library link is broken, the parameter "ReferenceBlock" is an empty array.
Part 2:
I misunderstood the issue. Once the libraries are loaded, they are on your MATLAB path and part of the workflow. Rehash doesn't remove items from the path, just cleans them up (you can check out the docs for what all goes on in the cleanup. Feel free to ask if you have specific questions).
I think what you are running into is the library blocks now being on your MATLAB path. The following outlines modifying the path and getting a list of all items on your path. https://www.mathworks.com/help/matlab/matlab_env/add-remove-or-reorder-folders-on-the-search-path.html
More Answers (0)
See Also
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!