Is the specific matlab procedure used in a matlab script?

I am running a large m file that I did not write myself, and it depends on certain subfunctions. I want to know if somewhere in all nested functions there is a certain function (in my case, the eig.m function is used (to calculate eigenvalues)). Is there a quick way to do this?

Regards, Koen

+6
source share
3 answers

You can use a semi-documented feature getcallinfo(see Yair Altman's blog for more information about it):

getcallinfo


          .

getcallinfo

script, ( Matlab R2016b ) 'filename.m '. , , script.

x = input('');
y = find(x);
z = f(norm(x));
disp(z)
function u = f(v)
    u = -log2(v) + log2(pi);
end

:

>> g = getcallinfo('filename.m');

, . g(1) . . g(2) f.

>> g(1).calls.fcnCalls
ans = 
  struct with fields:    
    names: {'input'  'find'  'norm'  'disp'  'log2'  'log2'  'pi'}
    lines: [1 2 3 4 6 6 6]

>> g(1).calls.innerCalls
ans = 
  struct with fields:    
    names: {'f'}
    lines: 3

>> g(2).calls.fcnCalls
ans = 
  struct with fields:    
    names: {'log2'  'log2'  'pi'}
    lines: [6 6 6]

>> g(2).calls.innerCalls
ans = 
  struct with fields:    
    names: {1×0 cell}
    lines: [1×0 double]

g ,

>> g(1).name
ans =
filename

>> g(2).name
ans =
f

>> g(1).type
ans = 
  Script with no properties.

>> g(2).type
ans =
subfunction

,

g, , calls.fcnCalls.names g:

g = getcallinfo('filename.m');
sought_function = 'log2'; % or 'eig' in your case
t = arrayfun(@(x) x.calls.fcnCalls.names, g, 'UniformOutput', false);
    % collect all names of called functions. Gives a cell array of cell arrays
    % of strings (character vectors)
t = [t{:}]; % de-nest: concatenate into cell array of strings
result = any(strcmp(t, sought_function)); % compare with sought function name
+6

profiler.

Matlab 2014, . , Luis Mendo, , -.

+1

, , .

, (. ), . , , , jacobianest, jacobianest.m, .

function jacobianest(args)
error('jacobianest is being used')
end 

, jacobianest.

1: . , edit *name of function* , . , .

0
source

All Articles