The function "mydepfun" determines the dependencies of an
M-file, ignoring files inside the MATLAB "toolbox" directory. Skipping these files gives significant performance improvements over calling "depfun" directly, especially in MATLAB installations which include multiple toolboxes. The assumption is the same as that in "mypath.m", i.e. that most of us do our work in directories outside $matlabroot/toolbox.
The function "exportToZip" creates a ZIP file containing all the dependencies identified by "mydepfun" for one or more MATLAB functions. This simplifies the process of passing your work to another user, or uploading it to MATLAB Central, by reducing both the effort required and the likelihood of a file being missed out.
The limitations of "depfun" apply: for example, that dependencies introduced by calls such as "eval('peaks')" are not identified. An additional limitation is that if files in the MATLAB toolbox directory somehow depend on files *outside* that directory (e.g.
if you have overloaded toolbox functions), these dependencies will not be picked up as they would by "depfun" itself.
The directory hierarchy is preserved by "exportToZip", which means that all required files must be on the same drive so that a "common root directory" can be determined.
This should really be part of Matlab -- it Just Works.
Just a quick shout out: if you want to include object-orientated code in your .zip, by default depfun and "mydepfun" won't find private methods of your objects. This is because they'll never be on your path (by definition) and you'll get errors like "error using depfun > next_arg_file. The file 'privateMethod' does not exist".
The solution to this is to change line 39 of exportToZip to read
I second mut ante's observation, and his suggestion for improvement. This function, which has earned a spot on my shortcut bar, fails in certain cases because of case sensitivity. I replaced all instances of STRNCMP with STRNCMPI in subfunction i_root_directory, and the problem went away.
Comment on Tim Tam comment:
look at the option 'recursive' of mydepfun.
exporttoZip uses this option so you get all dependencies.
26 Sep 2008
mydepfun does not appear to find dependencies of dependencies ? When I used ML's depfun it returned 30 non-toolbox m files (plus one custom DLL), while your mydepfun returned only 13 m files.
13 Sep 2006
Great! This is just what I needed. It's perfect for releasing code to a user and also a handy way of making a new directory without all the useless files that somehow get created on the way.
02 Jun 2006
hi: i have the habit of mixing upper and lower case when writing important folder names... the function worked properlly after changing the string comparison functions to the corresponding ignore case functions... well this is admissible in a win system, but.... thx for this function
17 Dec 2009
15 Mar 2010
Added copyright notice and upgraded string comparisons to strncmpi, which eliminates warnings from M-Lint.