Forget all known references or find all potentially broken references

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.

 Accepted Answer

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:
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

Probably, my original post is not clear. Here are pictures of Model1 before (Screenshot 1) and after (Screnshot 2) loading Model2. If I use find_mldlerefs('Model1') in the state of screenshot 1, no errors are thrown. If I use rehash toolboxcache (or any of the other rehash commands), in the state of screenshot 2, the loaded libraries are not forgotten. Including the commands close_system('Model1');open_system('Model1'); does not change this. Only a restart of Matlab, does suffice, currently.
Have you got other suggestions?
Screenshot 1:
Screenshot 2:
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
Your Part 2 offers the easiest solution for me, thank you! I just reset the path after I am done with one model.
old_path = path; %save a copy of original clean state of path
%load, work on, close model1 ... then:
path = old_path;
%load, work on, close model2 ... then:
path = old_path;

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!