Code covered by the BSD License  

Highlights from
exportToZip: Identifies the dependencies of an M-file and creates a ZIP file

4.45455

4.5 | 11 ratings Rate this file 27 Downloads (last 30 days) File Size: 3.62 KB File ID: #10702

exportToZip: Identifies the dependencies of an M-file and creates a ZIP file

by

 

11 Apr 2006 (Updated )

Files inside $matlabroot/toolbox are omitted, providing a useful way to package your work

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

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.

Acknowledgements

Depfun2, Dep Sub Fun, and Mypath.M inspired this file.

This file inspired Mydepfun Extended, Exporttozip, and Documenting (Help Section Of) An M File.

MATLAB release MATLAB 7.2 (R2006a)
Other requirements Should work on any platform (though has only been tested on Windows) and any release since R14 (MATLAB 7.*).
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
17 Nov 2014 Jack

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

req{i} = matlab.codetools.requiredFilesAndProducts(funcname{i});

which can handle objects properly.

28 Nov 2011 ingegnerisinasce Rossi

Simply great

13 Sep 2011 Michael Völker  
03 Aug 2011 Tobias Kienzler

great work! but you should change

if ~isempty(dirname) && dirname(1)=='@'

to

if ~isempty(dirname) && (dirname(1)=='@' || dirname(1)=='+')

to handle packages correctly as well

06 May 2011 Thomas Vanaret

In function "mydepfun", subfunction "i_function_name" may be corrected as following to treat correctly "private" directories :

function func = i_function_name(f)
% Identifies the function name for the specified file,
% including the class name where appropriate. Does not
% work for UDD classes, e.g. @rtw/@rtw

[dirname,funcname] = fileparts(f);
[ignore,dirname] = fileparts(dirname);

% [TV] patch for 'private' functions
if strcmp(dirname, 'private')
[ignore, private_parent] = fileparts(ignore);
dirname = private_parent;
funcname = [ 'private' filesep funcname ];
end
% /[TV] patch for 'private' functions

if ~isempty(dirname) && dirname(1)=='@'
func = [ dirname filesep funcname ];
else
func = funcname;
end

06 May 2011 Thomas Vanaret

"private" directories not treated by "i_function_name" subfunction, what causes errors / incorrect results

See "getFileDependencies" in Matlab FEX

06 Mar 2011 per isakson

exportToZip cannot handle packages(?)

??? Error using ==> depfun>next_arg_file at 1423
The file 'MemmapAdapter' does not exist.
....
Error in ==> mydepfun>i_scan at 69
list = depfun(func,'-toponly','-quiet');

where 'MemmapAdapter' is an m-file in a package.

Is "packages" on your TODO-list?

/per

08 Oct 2010 dk  
21 Dec 2009 Brett Shoelson

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.

19 Nov 2008 Thierry Dalon

Comment on Tim Tam comment:
look at the option 'recursive' of mydepfun.
exporttoZip uses this option so you get all dependencies.

26 Sep 2008 Tim Tam

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 Murphy O'Brien

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 mut ante

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

Updates
17 Dec 2009

Review

15 Mar 2010

Added copyright notice and upgraded string comparisons to strncmpi, which eliminates warnings from M-Lint.

Contact us