MATLAB: Does “requiredF​ilesAndPro​ducts” fail to find the function when “which” is able to find it

MATLABpackagerequiredfilesandproductsundefined

I am using "requiredFilesAndProducts" to try and find all dependencies of my function, but it is failing to work, saying it cannot find my function. Here is the command I am using:
>> [fList,pList] = matlab.codetools.requiredFilesAndProducts('packageName.functionName.m');
Which gives the error:
Error using matlab.codetools.requiredFilesAndProducts (line 91)
File, function or class "packageName.functionName.m" may not exist. Neither WHICH nor EXIST could find an exact, case-sensitive match. Please check the spelling of the name, and that any required directories are on the MATLAB path.
However, "which" is able to find the file:
>> which packageName.functionName
returns the path to the file.
Why is "requiredFilesAndProducts" not working?

Best Answer

For files in a package, you need to input the file name without the '.m' on the end of it, so if you change your command to:
>> [fList,pList] = matlab.codetools.requiredFilesAndProducts('packageName.functionName');
you should get the output you expect.
Similarly, if you were to run the "which" command with the '.m' included, it would return zero results:
>> which packageName.functionName.m
This is the implied "which" call that your previous instance of "requiredFilesAndProducts" was calling.
The reason the '.m' cannot be on the name is because the file is in a private package - it is effectively a method of the package name, rather than a normal script or function. For example, you cannot call your M file from outside the package with the '.m' included in the name either - it would return an "undefined variable" error.
Another tool that you may find useful for your work is the Dependency Report, which provides more in-depth information than "requiredFilesAndProducts". You can read more about the Dependency Report on the following documentation page: