Find functions used in a specific Matlab toolbox

I am porting my code and should reduce the number of toolkits used as much as possible. For example, I have a large script file that uses several toolkits. I can find them with

[fList,pList] = matlab.codetools.requiredFilesAndProducts('myscript.m'); 
display({pList.Name}');

I get the following result

'Image Processing Toolbox'
'Instrument Control Toolbox'
'MATLAB'
'Model-Based Calibration Toolbox'
'Signal Processing Toolbox'
'Statistics and Machine Learning Toolbox'
'Parallel Computing Toolbox'

Is there an easy way to find out which functions are used from this particular toolkit in my script file? For example, how can I find out which function is 'Model-Based Calibration Toolbox'used in my code? Or in which line of code is this toolbar used? Thus, I can try to implement this function myself and not use the toolbar.

. , , , ( ). , gui .

+4
1

, , getcallinfo:

g = getcallinfo('filename.m');
f = g(1).calls.fcnCalls.names;

, g - . g(1) , f - , . f (, g(1).calls.fcnCalls.lines). , which:

cellfun(@(x) which(x), unique(f))

unique . , , , which, , .


perms.m :

>> g = getcallinfo('perms.m')

>> g(1)
ans = 
  struct with fields:

              type: [1×1 internal.matlab.codetools.reports.matlabType.Function]
              name: 'perms'
          fullname: 'perms'
    functionPrefix: 'perms>'
             calls: [1×1 struct]
         firstline: 1
          lastline: 37
          linemask: [61×1 logical]

>> g(2)
ans = 
  struct with fields:

              type: 'subfunction'
              name: 'permsr'
          fullname: 'perms>permsr'
    functionPrefix: 'perms>permsr'
             calls: [1×1 struct]
         firstline: 40
          lastline: 61
          linemask: [61×1 logical]

>> f = g(1).calls.fcnCalls.names
f =
  1×8 cell array
    'cast'    'computer'    'error'    'factorial'    'isequal'    'length'    'message'    'numel'

>> cellfun(@(x) which(x), unique(f))
built-in (C:\Program Files\MATLAB\R2016b\toolbox\matlab\datatypes\cast)
built-in (C:\Program Files\MATLAB\R2016b\toolbox\matlab\general\computer)
built-in (C:\Program Files\MATLAB\R2016b\toolbox\matlab\lang\error)
C:\Program Files\MATLAB\R2016b\toolbox\matlab\specfun\factorial.m
built-in (C:\Program Files\MATLAB\R2016b\toolbox\matlab\elmat\isequal)
built-in (C:\Program Files\MATLAB\R2016b\toolbox\matlab\elmat\length)
message is a built-in method  % message constructor
built-in (C:\Program Files\MATLAB\R2016b\toolbox\matlab\elmat\numel)
+4

Source: https://habr.com/ru/post/1681616/


All Articles