Created
July 9, 2014 09:24
-
-
Save stefanSchinkel/b403d3b305515caaf32d to your computer and use it in GitHub Desktop.
A simple matlab function to solve the dependencies for a function. Might be useful when deploying a single function from a larger package.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function files = findRequiredFunctions(mainFun) | |
% FINDREQUIREDFUNCTIONS- solve file dependencies | |
% | |
% function files = findRequiredFunctions(mainFun) | |
% | |
% Find ALL files that are called by as function | |
% provided as MAINFUN, which are not part of the | |
% default Matlab installation. | |
% | |
% The general behaviour is covered by DEPFUN, but | |
% this will return a huge amount of files and take | |
% quite a long time to run. This implementation only | |
% queries the topmost dependent functions, but his | |
% recursively. | |
% | |
% | |
% Input: | |
% fun = name of function | |
% | |
% Output: | |
% files = cell array with all files | |
% | |
% | |
% Requires: depfun | |
% | |
% See also: -- | |
if nargin < 1 | |
% the function of interest | |
help(mfilename) | |
return | |
end | |
% find top only depencies | |
fileList = depfun(mainFun,'-toponly','-quiet'); | |
% aquire indeces of all files not in matlabpath | |
res = cellfun(@(x) strfind(x,matlabroot) ,fileList,'UniformOutput',0); | |
idx = find( cellfun(@isempty,res) ); | |
% assing match files to output | |
% the first hit always matches input | |
files = {}; | |
files = [files fileList{ idx(2:end) }]; | |
% loop over found files | |
for iRes = 2:numel(idx) | |
% recursivly loop over input until all files are matched | |
fprintf('Working on %s \n',fileList{idx(iRes)}); | |
files = [files findRequiredFunctions(fileList{idx(iRes)}) ]; | |
end %iRes | |
% unique output, since some functions may | |
% call the same function | |
files = unique(files); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment