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.
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.
This function uses an obsolete function (depfun), and therefore can't run on new Matlab releases
Friend, I owe you a drink. At the very least.
This worked perfectly for me in R2009b.
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.
There's a bug in the code (alluded to by Jedediah above). You need to check line 37.
"IS_recursvie = false;"
"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.
Oh yeah, I use 2010a
Works fine for me.
Maybe if you actually used the same matlab version (R2010B), as clearly stated in the above file information.
Doesn't work. Fails immediately:
??? Input argument "IS_recursive" is undefined.
Error in ==> deppkg at 67
MATLAB Version 184.108.40.2065 (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.