Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here are a couple of links I found helpful when I wrote up a simple function to create a <a href="http://www.mathworks.com/matlabcentral/fileexchange/20164" rel="nofollow noreferrer">table of contents for an m-file</a>:</p> <ul> <li>A thread discussing the undocumented function <a href="http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/145245" rel="nofollow noreferrer">MLINTMEX</a></li> <li><a href="http://www.mathworks.com/matlabcentral/fileexchange/17291" rel="nofollow noreferrer">FDEP</a> by Urs Schwarz on the MathWorks File Exchange</li> <li><a href="http://www.mathworks.com/matlabcentral/fileexchange/15924" rel="nofollow noreferrer">FARG</a> by Urs Schwarz on the MathWorks File Exchange</li> </ul> <p>EDIT: Since this problem piqued my curiosity, I started trying out a few ways I might approach it. Finding the dependencies on non-toolbox .m and .mex files was relatively trivial (I did this in MATLAB version 7.1.0.246):</p> <pre><code>fcnName = 'myfile.m'; fcnList = depfun(fcnName,'-quiet'); listIndex = strmatch('C:\Program Files\MATLAB71\toolbox',fcnList); fcnList = fcnList(setdiff(1:numel(fcnList),listIndex)); </code></pre> <p>Here, I just used <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/depfun.html" rel="nofollow noreferrer">DEPFUN</a> to get the dependencies, then I removed any files that began with 'C:\Program Files\MATLAB71\toolbox', where the MATLAB toolboxes are located on my machine. Note that this assumes you aren't placing any of your own code in these MATLAB directories (which you shouldn't do anyway).</p> <p>To get dependencies on .mat and .txt files, I took another approach. For each of the files you get from the above code, you could load the text of the file into MATLAB and parse it with a regular expression to find strings that end in a '.mat' or '.txt':</p> <pre><code>fid = fopen(fcnName,'rt'); fcnText = fscanf(fid,'%c'); fclose(fid); expr = '[^\'']\''([^\''\n\r]+(?:\w\.(?:mat|txt)){1})\''[^\'']'; dataFiles = regexp(fcnText,expr,'tokens'); dataFiles = unique([dataFiles{:}]).'; </code></pre> <p>There are a few limitations to the regular expression I used:</p> <ul> <li><p>If you have a string like 'help.txt' that appears in a comment (such as the help comment block of a function), it will still be detected by the regular expression. I tried to get around this with a lookaround operator, but that took too long to run.</p></li> <li><p>If you build a string from variables (like "fileString = [someString '.mat']"), it will not be detected by the regular expression.</p></li> <li><p>The returned strings of file names will be relative path strings. In other words, if you have the strings 'help.txt' or 'C:\temp\junk.mat' in the function, the regular expression matching will return 'help.txt' or 'C:\temp\junk.mat', exactly as they appear in the function. To find the full path, you can use the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/which.html" rel="nofollow noreferrer">WHICH</a> function on each data file (assuming the files reside somewhere on the MATLAB path).</p></li> </ul> <p>Hope you find these useful! =)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload