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?

 Akzeptierte Antwort

dpb
dpb am 30 Apr. 2026 um 14:07
Verschoben: Matt J vor etwa 23 Stunden
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 Kommentar

+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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 30 Apr. 2026 um 12:47

Kommentiert:

vor etwa 22 Stunden

Community Treasure Hunt

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

Start Hunting!

Translated by