View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
M-file dependency consolidator

3.8 | 4 ratings Rate this file 4 Downloads (last 30 days) File Size: 1.92 KB File ID: #31164 Version: 1.1

M-file dependency consolidator


Jit (view profile)


22 Apr 2011 (Updated )

Will take a given m-file, or directory of such files, and consolidate any dependent m/mex files

| Watch this File

File Information

This function will take a given m-file, or directory of such files, and copy all necessary related function files (m and mex) to the target directory, excluding any MatLab provided ones (e.g. toolboxes).

I often have to distribute my code to others who'd like run similar numerical models, (un)fortunately my software-engineer mindset means a lot of reused functions, scattered over a number of organized 'tool' folders in my matlab path.
This makes packaging everything needed to give to someone else a bit difficult.
MatLab provides a dependency report tool, but it isn't recursive, and does not provide the ability to even open the dependent files, let alone copy them.

My search for a solution turned up 2 promising functions in File Exchange, but neither worked for me - and when I tried to edit them, it was apparent that they were far more cluttered than needed to be.

So I wrote my own from scratch.
I hope it will be useful for others as well.

Known issues:
if the same dependent function is encountered in multiple source files (directory traversal), it is copied multiple times and will have multiple entries in output file list.
I'm not sure how to avoid this without complicating the recursion too much.


Package inspired this file.

MATLAB release MATLAB 7.11 (R2010b)
Other requirements uses only matlab function calls, so should be platform independent
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
06 Jul 2016 Noam Greenboim

This function uses an obsolete function (depfun), and therefore can't run on new Matlab releases

Comment only
20 Dec 2012 Paul

Paul (view profile)

Friend, I owe you a drink. At the very least.

27 Feb 2012 Mike

Mike (view profile)

This worked perfectly for me in R2009b.

26 Apr 2011 Jit

Jit (view profile)

Thanks, I found the typo further down as well.
Odd, because it worked for me even with the typo...

I flip-flopped on how I wanted it to behave on the input, but I usually do something like:

Hence why I wouldn't want the src copied too.
I thought it might also be an issue for directory recursion, and also why I forced it to not drill down directories on SRC, but now I'm thinking I could just set it up to check for DEST paths in the source, and skip those.

Jedediah: Could you see if the new version works for you now? I'd like to make it work for earlier matlab releases as well, as long as it's not too much work - but no longer have access to the older releases myself.

Comment only
26 Apr 2011 Gordon

Gordon (view profile)

There's a bug in the code (alluded to by Jedediah above). You need to check line 37.

"IS_recursvie = false;"

should be

"IS_recursive = false;"

Once I fixed that, this worked great on the file I threw at it. I actually like turning recursive on: if I'm copying all the dependencies to a directory, I probably want the source file in there too.

Sorry for the double post.

Comment only
26 Apr 2011 Gordon

Gordon (view profile)

Oh yeah, I use 2010a

25 Apr 2011 Jit

Jit (view profile)

Works fine for me.
Maybe if you actually used the same matlab version (R2010B), as clearly stated in the above file information.

Comment only
25 Apr 2011 Jedediah Frey

Jedediah Frey (view profile)

Doesn't work. Fails immediately:
>> deppkg('print_problem2','test')
??? Input argument "IS_recursive" is undefined.

Error in ==> deppkg at 67
if IS_recursive
MATLAB Version (R2009b) Service Pack 1

26 Apr 2011 1.1

Fixed typo identified by Gordon and Jedediah.

Also fixed an error in the file list output - it was including files that were skipped as well.

Contact us