View License

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

» Watch video

Highlights from
Publish dependent and called functions

4.7 | 7 ratings Rate this file 96 Downloads (last 30 days) File Size: 4.55 KB File ID: #33476 Version: 1.6

Publish dependent and called functions


Nick Angelini (view profile)


26 Oct 2011 (Updated )

Publish explicitly called functions not found in the MATLAB root. See mfile for limitations.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

  publishdepfun creates a single published html file with called
  functions attached to the end of the root mfile. Hyperlinks will be
  within a "Called Functions" in the Table of Contents area of the
  published document that link to the called function. Functions that are
  called that are under MATLABROOT are not included in the published
  publishdepfun only goes one level deep....
  Example: If fun1 calls fun2, fun2 will be published. If fun2 calls fun3,
           fun3 will not be published.
  Calling: new_doc = publishdepfun(func,opts)
  * func => character string of root function or script ('Function1').
            The ".m" is not needed.
  * opts => is the list of options for the publishing. See publish.m help
            for more information.
 * add_fun => is a cell array of additional functions to be published.
 * rm_fun => is a cell array of functions to remove from publish list.
  * new_doc => the final html document with attached subfunctions.
                    Name is the root file name with "_withfuncs" appended.


This file inspired Publish The Main And The Subfunctions Together.

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
08 Dec 2016 Krishnaraj Sambath

Works perfectly!

17 Jul 2015 Ting Zhou

Says depfun was removed. Any ideas?

Comment only
03 Feb 2015 YX Sun

YX Sun (view profile)

17 Sep 2014 Valeria

Hi, is there a way to avoid multiple publishing of subfunctions that are called multiple times? Let's say for instance that I have created an auxiliary function that needs to be called twice with different argumetns. This way your tool will list it in the Called Functions twice and will attach it at the end of the document twice.
Thank you.

Comment only
13 May 2014 Denis Anikiev

30 May 2013 Nick Angelini

Nick Angelini (view profile)

@jon there is not going to be a pdf version. This is simply spliced html code together. MATLAB uses a completely different method for creating pdfs. If you want pdfs look at the "Publish The Main And The Subfunctions Together". It creates a new mfile with all your functions then publishes it.

I don't know what you mean by doesn't publish first script alongside your functions.

The example makes two files. It creates a published file of all the files it thinks it needs and copies code from them into the "withfuncs" file.

If you think the code is not working properly either give me more info or send me the files so I can look at it.

Comment only
24 May 2013 jon

jon (view profile)

Close but doesn't have pdf or publish my first script alongside my functions.

I have two separate files.. myfile & myfilewithfuncs. They are not a single file like the example makes.

I have two functions in separate scripts along with my main file. I also have one inline function.

05 Feb 2013 Nick Angelini

Nick Angelini (view profile)

Updated to include ability to remove functions from publish list.

I can look into adding pdf output if I have time. It would take some effort considering I am splicing this together with html code and the default publish function does not create html code before making the pdf.

Comment only
31 Jan 2013 Michael

This is great. I was wandering though if there is a way to suppress a particular function file? I am running a student version and I do not have the toolbox that includes the roundn function, so I am using one found here. I would rather this function not be published in order to keep my overall report looking better.

Comment only
20 Nov 2012 SeungGyu cho

you're a jewel.

15 Oct 2012 Wang Jing

Great job! It will be perfect if the output can be pdf.

29 Sep 2012 Mohammad

Thanks for this code! It helped me to combine everything nicely for my programming class.

However, is there a way to combine everything into a .pdf? I'm currently copying everything published in HTML to Word and saving as a .pdf.

Comment only
19 Mar 2012 Jiro Doke

Jiro Doke (view profile)


Thanks for adding the web output in case of no output argument. "nargout" is the appropriate way to deal with that.

Comment only
06 Mar 2012 Arvind

Arvind (view profile)

Thanks Nick... This is exactly what I needed

Comment only
13 Feb 2012 Nick Angelini

Nick Angelini (view profile)


Thanks for finding that. I have added it to the file and have submitted the updated version.

Comment only
07 Feb 2012 Mikhail

Mikhail (view profile)


However, it also includes my called MEX functions into the generated report (which looks kinda weird in the report).

I added the following around line 95 to mitigate this particular behavior:

%% Remove hits that are probably MEX functions
for i=1:length(idx),
idxs(i) = ~isempty(idx{i});

Comment only
23 Jan 2012 Nick Angelini

Nick Angelini (view profile)


I have added some crude support for displaying the html document when no output argument is given. I just used nargout. Is there a more elegant solution?

Comment only
19 Jan 2012 Jiro Doke

Jiro Doke (view profile)

Very nice entry Nick!

This may be about preference, but it would be nice if I call the function without any output argument, then it would open the published HTML in the MATLAB browser. This is the same behavior as "publish".

Otherwise, I really like it. I plan on highlighting this entry for this week's Pick of the Week.

Thanks for the submission!

10 Jan 2012 1.1

Version 2
# added ability to pass additional functions as a cell array to be published.
# added '-calltree' opition to the depfun call to find the functions
passed into other functions like ode's and quad.

20 Jan 2012 1.2

Changed title

23 Jan 2012 1.3

Added support for displaying published html document if no output variable is specified.

23 Jan 2012 1.4

Added support for displaying published html document if no output variable is specified.

13 Feb 2012 1.5

added ability to remove mex files from output

05 Feb 2013 1.6

added ability to add user list of functions that are not to be published

Contact us