Easier (and less error-prone) creation of Zip files
Brett's Pick this week is exportToZip, by fellow MathWorker Malcolm Wood.
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!
- 범주:
- Picks
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.