I generate a call graph of a complex MATLAB system, and I want to know which functions are built-in and mark them.
Although I think solutions based on which
are better, for completeness, we should also consider the function exist
for this. From the documentation:
exist name
returns the type ofname
as a number. This list describes the type associated with each value:
0 —
name
does not exist or cannot be found for other reasons. For example, ifname
exists in a restricted folder to which MATLAB® does not have access,exist
returns 0.1 —
name
is a variable in the workspace.2 —
name
is a file with extension.m
,.mlx
, or.mlapp
, or name is the name of a file with a non-registered file extension (.mat, .fig, .txt
).3 —
name
is a MEX-file on your MATLAB search path.4 —
name
is a loaded Simulink® model or a Simulink model or library file on your MATLAB search path.5 —
name
is a built-in MATLAB function. This does not include classes.6 —
name
is a P-code file on your MATLAB search path.7 —
name
is a folder.8 —
name
is a class. (exist returns 0 for Java classes if you start MATLAB with the-nojvm
option.)
So when we try this on the examples shown earlier:
>> exist eig
ans =
5
>> exist solve
ans =
2
>> exist nosuchfunction
ans =
0