Forget all known references or find all potentially broken references

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Devon
Devon am 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:
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 Kommentare
Devon
Devon am 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
Alexander Boll
Alexander Boll am 15 Nov. 2023
Bearbeitet: Alexander Boll am 15 Nov. 2023
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;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by