How can I automatically find the input files a function or script uses?

The "matlab.codetools.requiredFilesAndProducts" function will return a list of program files needed for a program, but it will not include input files that the program loads, such as .mat files, a read of a spreadsheet or text file, etc. How can I automatically find all dependencies for a program that includes all input files needed?

 採用された回答

dpb
dpb 2026 年 4 月 30 日 14:07
移動済み: Matt J 2026 年 5 月 1 日 12:35
Static analysis can't unless everything is hardcoded...and then would have to parse the code to find the pieces-parts making up the filenames.
function res=myfunc(fn)
data=readmatrix(fn);
...
res=...;
end
What is the above supposed to return for the most simple of issues...
Or, another very common coding paradigm...
d=dir('*.xlsx');
for i=1:numel(d)
tData=readtable(fullfile(d(i).folder,d(i).name));
...
end
Here one could in theory go do the dir() listing but the results can be changed at any time.

1 件のコメント

Stephen23
Stephen23 約22時間 前
+1 Two identical copies of the same function Mfile saved in two different directories could access very different data files and call completely different functions (of the same name), even if everything is "hardcoded". Static analysis is certainly no substitute for runtime!

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2026 年 4 月 30 日 12:47

コメント済み:

2026 年 5 月 1 日 13:50

Community Treasure Hunt

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

Start Hunting!

Translated by