File Exchange

image thumbnail

M-file dependency consolidator

version 1.1 (1.92 KB) by

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



View License

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.

Comments and Ratings (8)

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


Paul (view profile)

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


Mike (view profile)

This worked perfectly for me in R2009b.


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.


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.


Gordon (view profile)

Oh yeah, I use 2010a


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.

Jed F.

Jed F. (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



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.

MATLAB Release
MATLAB 7.11 (R2010b)

Inspired by: package

Inspired: Project Release ZIP File from Dependencies

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

» Watch video

Win prizes and improve your MATLAB skills

Play today