필터 지우기
필터 지우기

Forget all known references or find all potentially broken references

조회 수: 3 (최근 30일)
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.

채택된 답변

Devon
Devon 2023년 11월 10일
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
Devon
Devon 2023년 11월 13일
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 2023년 11월 15일
편집: Alexander Boll 2023년 11월 15일
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;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by