Get references and check for shadowed files before opening a model
이전 댓글 표시
If I open a model with load_system() I eventually get a lot of warnings caused by referenced dictionaries, libraries, etc. that have shadowed files on the path.
How do I find all those shadowed files before using load_system() so that I can take care of those shadowed files and eventually remove them or from the path?
(Clearing the whole path is not acceptable!)
Thanks for your suggestions.
답변 (1개)
Soumya
2025년 10월 30일
이동: Walter Roberson
2025년 10월 30일
Hi Marcus,
I understand you're seeing warnings from shadowed files when using load_system() due to multiple versions of referenced models, libraries, or data dictionaries on your MATLAB path. This is a common issue, and MATLAB provides documented tools to help you detect and resolve these conflicts before loading your model.
You can refer to the following troubleshooting steps:
- Use 'find_mdlrefs' to retrieve all referenced models in your top-level Simulink model — the function temporarily loads referenced models and returns 'refModels' (names of referenced models) and 'modelBlocks' (paths to Model blocks referencing them):
load_system('yourModelName');
[refModels, modelBlocks] = find_mdlrefs('yourModelName');
- Use matlab.codetools.requiredFilesAndProducts to list all files and products needed to run or simulate your model:
[files, products] = matlab.codetools.requiredFilesAndProducts('yourModelName');
- Use the documented which function with the -all flag to detect multiple instances of the same file on your path:
for i = 1:length(files)
[~, name, ext] = fileparts(files{i});
locations = which([name, ext], '-all');
if numel(locations) > 1
fprintf('Shadowed file detected: %s\n', [name, ext]);
disp(locations);
end
end
You can refer to the following documentations for more information:
- https://www.mathworks.com/help/simulink/slref/find_mdlrefs.html
- https://www.mathworks.com/help/simulink/ug/manage-shadowed-and-dirty-model-files.html
- https://www.mathworks.com/help/matlab/ref/which.html
- https://www.mathworks.com/help/matlab/ref/matlab.codetools.requiredfilesandproducts.html
I hope this helps!
카테고리
도움말 센터 및 File Exchange에서 Interactive Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!