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.

Answers (1)

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:
I hope this helps!

Categories

Products

Release

R2024b

Asked:

on 27 Oct 2025

Moved:

on 30 Oct 2025

Community Treasure Hunt

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

Start Hunting!