I recently received an email from a File Exchange user informing me that a GUI I had shared for morphologically processing images (i.e., morphTool) didn't work. As it turns out, I had neglected to include in the Zip file that I uploaded a couple of functions that were called internally by morphTool.
I've made the same mistake before, and I've also downloaded File Exchange files that were missing some key functionality.
This email exchange had me thinking about writing a bit of code to automatically create my Zip files, making sure to include all necessary supporting function files. MATLAB has a depfun command that will thoroughly analyze a function and determine its dependencies, including, by default, functions in MATLAB Toolboxes. It can take a little while to generate a report, though, and does a lot more work than is necessary just to create a comprehensive Zip file. Alternatively, one can easily create a dependency report for the current file active in the MATLAB editor by using "Save and Show Dependency Report" from the Tools menu. That approach is much faster than using depfun (with its default options), but leaves you then to manually evaluate one-by-one each function that your top-level function calls. As you might guess, it's easy to miss a necessary file when you create your Zip.
Before I started coding, I thought I'd check the File Exchange (wouldn't you?), and I quickly found Malcolm's exportToZip. Malcolm's file uses his own version of depfun (called mydepfun), that smartly uses non-default behavior of depfun to automatically skip files in MATLAB Toolboxes; mydepfun returns the paths to just those files needed for the target Zip file, which is then automatically created.
I tried exportToZip on morphTool; it worked flawlessly--and quickly! And syntactically, it couldn't be easier to use:
zipfilename = exportToZip(funcname,zipfilename)
Oh, and incidentally, a new version of morphTool will go live soon. Thanks, Malcolm--you saved me a lot of time and effort!
You gotta love the File Exchange!
Get the MATLAB code
Published with MATLAB® 7.8
7 CommentsOldest to Newest
As a much beefed-up improvement on depfun, I love Urs’s fdep utility on the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/17291
Urs has contributed some great tools over the years. I wasn’t familiar with FDEP; thanks for pointing that out.
I wrote a zip function like this a while back, but the problem I have is that depfun is broken for me. It thinks that the legend command depends on a bunch of my functions, so anything using legend drags in dozens of unrelated functions. Something in the internal scribe class or something as I recall. It’s certainly path related, but not because my functions are ahead of the toolboxes on the path – they aren’t. It seems to be a reporting error on depfun’s part rather than a real dependency.
I’m sorry you’re having problems with the DEPFUN command. Our Development Team is very interested in your feedback whenever you have issues with our code (or suggestions for enhancements!). I’d like to suggest that you enter a service request to report and track the issue–it’s easy to do, and helps us to continually improve your MATLAB experience. To report the issue, you’d GOTO our home page (www.mathworks.com), CLICK on the “Suport” tab, SELECT “View Service Requests” (under the “Manage My Account” heading), then, on the left panel under “My Support,” SELECT “Create New Request.” (Select the “Technical Support” option, and enter the relevant information.)
If you have any problems reporting the issue, feel free to email me directly:
char(cumsum([98 16 -13 15 0 -70 69 -11 7 -10 7 7 -4 -1 -46 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2]))
and I’ll be glad to help you out.
It’s a shame, but depfun(…) does not properly return the dependencies of Matlab script files. For example, it does not always find where Matlab classes are created.
This unfortunately means that exportToZip may omit required files if there are any script .m files called at ANY POINT from the file being exported or its children.
It’s a pity.
Thanks for the comment, Chris. Dependency mapping is challenging for a number of reasons, but we’re constantly working on trying to improve the process. I’ve shared your comments with the Developers responsible for DEPFUN.
I tried many different way to find if there is any way to find missing dependency function in matlab. what I mean by missing functions is suppose we have a function(parent) which calls another function(children). normally if you use DEPFUN it will recognize children function but if children function has been deleted from the PC then the DEPFUN is not able to list it as dependency function.
I was wondering if someone has an idea how to recognize these type of children functions.
Thanks in advance,