Reputation: 2893
A runtime error occurs when the Matlab interpreter interprets a function that isn't implemented in an .m - file. Is there a way to find these errors at "compile time", i.e., is there a script that parses my matlab code, checks all called functions and tells me which .m - files are missing (with regard to my defined paths)?
Upvotes: 4
Views: 806
Reputation: 3355
Quick answer: No.
Depfun would have been my first guess as a solution for this problem, but it only gives you a list of the dependencies that exist on the path, not those that do not exist. Likewise, mlint and mlintmex are not as useful for this as I would have hoped.
I believe that the reason for this is as follows: The syntax for function calls and subscripts are identical in MATLAB.
The only way to tell if foo(bar) is a function call to "foo.m" or an attempt to subscript into a matrix "foo", is to execute the code up to that point, and see if a matrix "foo" exists in scope and/or if foo.m exists on the path. If both exist, then MATLAB's precedence rules decide if the symbol "foo" gets treated as a function call or as a subscripting operation.
In the following toy example, the expression "ambiguous(1:9)" gets treated first as a function call, then as a subscripting operation:
function test
disp( ambiguous( 1:9 ) )
ambiguous = 'data item';
disp( ambiguous( 1:9 ) )
end
function szMsg = ambiguous( anArgument )
szMsg = 'function call';
end
It is also possible to create variables using eval and evalin, and to manipulate the MATLAB path to bring m-files in and out of scope. These reasons all conspire to make the solution to this problem impractical (and perhaps even impossible) for the general case.
Upvotes: 2