forked from kndiaye/matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepfuntoolbox.m
62 lines (51 loc) · 2.02 KB
/
depfuntoolbox.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function Files = depfuntoolbox(input)
%DEPFUNTOOLBOX Locate dependent functions of an M/P-file by toolbox
%
% Files = depfuntoolbox(filename)
% Files = depfuntoolbox(traceList)
%
% This function uses the depfun function to determine the dependent
% functions of any m or p file, and then separates the files based on the
% Matlab toolbox to which they belong.
%
% Input variables:
%
% filename: string with m or p filename
%
% traceList: cell array output of depfun function
%
% Output variables:
%
% Files: 1 x 1 structure. Each field is the name of a toolbox
% directory (for example, matlab = base Matlab, stats =
% Statistics Toolbox, map = Mapping Toolbox, etc) and holds a
% cell array of dependent function names associated with that
% toolbox. Dependent functions that are not part of a Matlab
% toolbox are listed under the fieldname 'other'.
% Copyright 2006 Kelly Kearney
%----------------------------
% Check input, run depfun if
% necessary
%----------------------------
if ischar(input)
allFiles = depfun(input, '-quiet');
elseif iscell(input)
allFiles = input;
else
error('Input must be a filename or cell array output of depfun');
end
%----------------------------
% Separate by toolbox
%----------------------------
matlabToolbox = fullfile(matlabroot, 'toolbox');
nchar = length(matlabToolbox);
isNotMatlabProper = cellfun(@isempty, strfind(allFiles, matlabToolbox));
matlabFiles = allFiles(~isNotMatlabProper);
matlabFiles2 = cellfun(@(a) a(nchar+2:end), matlabFiles, 'UniformOutput', false);
toolboxName = cellfun(@(a,b) a(1:b(1)-1), matlabFiles2, strfind(matlabFiles2, filesep), 'UniformOutput', false);
uniqueToolbox = unique(toolboxName);
filesInToolbox = cellfun(@(a) matlabFiles(strcmp(a, toolboxName)), uniqueToolbox, 'UniformOutput', false);
Files = cell2struct(filesInToolbox, uniqueToolbox, 1);
if any(isNotMatlabProper)
Files.other = allFiles(isNotMatlabProper);
end