File Exchange

image thumbnail


version (21.6 KB) by Christopher Pedersen
plots the subroutines in a function, and their dependencies on each other


Updated 07 Dec 2016

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

plot_subfun('foo.m') plots a node map of the subroutines in the file foo.m, and their dependencies.
The screenshot is a sample output for the function plot_subfun.m itself.
There is a demo of examples which can be shown with web(publish('demo_subfun'))

Cite As

Christopher Pedersen (2021). plot_subfun (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (35)

Adrien Thabuis

Dominik Sasin

Very nice tool!
I see one space for improvement. With recent MATLAB versions is it possible to call a function from the package and this tool is not sensitive for it.
Calling: out = package1.package2.example_fun();

It would be very helpful to add this feature.


This function is very cool.
Perfectly worked with latest MATLAB releases.

In my case, current version of plot_subfun does not seem to detect annonymized functions.
For example,
calls getresidual function through the annonymous function, but I cannot find the getreisudal function in figure made by plot_subfun.


Thanks for catching those, Amro. Code has been fixed.


Two fixes I made:
- in plot_graph, fix typo s/leyboard/keyboard/
- in plot_subfun>sub_show_unhide, replace "opt.edge.index" with "opt.edge.nodeindex"


Good Settings: '-extsub','-nomain'

David Sanz

Really great :-) Thanks for sharing!

Christopher Pedersen

Hi all,
Apparently Sean has been having issues with this under windows 7, that it only generates the figure if you ask for an output:
plot_subfun('plot_subfun') does nothing.
resu = plot_subfun('plot_subfun'); does generate the figure.
If anyone else is having the same issue, please get in touch.

seth sun

Thanks Christopher!
I have a question. When I use your scripts for GUI, it only plot input and output of the GUI. Is it possible to show the functions list in a GUI?


Run plot_subfun('plot_subfun','-unhide')
got nothing outputed. Should I expect a tree graph output?



Chris FUNG

Carl Wouters

Thanks Christopher !
Works perfectly now :-)

It would be even more perfect if you could add Matlab Classes ;-)

Christopher Pedersen

Bruce, Carl - the problem is that I was a total idiot, and uploaded the wrong file.

I'm absolutely mortified.

Carl Wouters

This looks like a very nice function, but I get errors:

"Undefined function 'plot_graph' for input arguments of type 'cell'." on line 17 of depfun and line 120 of sub_plot.

Also in the zip file there are only 2 files (plot_depfun and plot_graph)

Bruce Elliott

I'm confused. This function (ID #46070) is supposed to be plot_subfun, right? I downloaded the Zip and got plot_depfun.m and plot_graph.m. Is that what was intended?

Christopher Pedersen

Bruce, Paul : I have added an option -extshow that will include external function calls in the figure. It can't "dig in" to those external functions to examine their subroutines... Still pondering how to do this.


Thanks for the nice, useable submission. I would just like to support the request of Bruce --- All my subfunctions are usually stored in external files, and these subfunctions contain their own subfunctions, also stored in external files. So I would really be able to start using plot_subfun if the calls to external functions are added to the figure.

Christopher Pedersen

@bruce. It's possible to add calls to external functions to the figure. I've added your suggestion to the to-do list.

Christopher Pedersen

@alexander Thanks for the feedback. I uploaded a new version yesterday that should work with windows32 and folders with space in them. Just for clarification of your last problem : do the figures appear on the screen when you run publish, but they don't make it into the html, or do they not appear at all ?

@Maria. Hi - it looks like you might be trying to call plot_graph directly, without using plot_subfun, is that correct ?
Can you email me directly with the details of what you're trying to do, and I'll see if I can help ?


Playing with this a bit more (but not having spent a lot of time looking at the code), how difficult would it be to extend it's reach? In particular, I'm thinking about the case where routine "main_program.m" calls a function called "sub_function" which is stored in "sub_function.m". Is there a way to get plot_subfun to go looking for sub_function.m somewhere on the path and include it's calls in the represented tree?

Alexander Mering

Hello Christopher,

this is really nice. Unfortunately I experienced some (minor) issues here:

a) In sub_mwdot_call(opt) you get the location of the 'mwdot.exe'. In my case it is located in ...\bin\win32 . The "32" is not automatically included currently and thus an error results. I had to add it by hand:

opt.mwdot.file = fullfile(matlabroot,'bin',[fol, '32'],foo)

b) It seems that the syntax in line 205 does not like folders with spaces in its name (like "New Folder"). = ['"' opt.mwdot.file '" -Tplain ' opt.mwdot.infile];

Could you confirm?

c) For some reason, my R2014b does not display any diagram for the demo. In R2011b this works. There is no error or message at all. Any idea?

Thanks for your submission.

Win 7 - R2014b

Maria Iftikhar


I am new to MATLAB. I am getting the following error when trying to use your function.
Cell contents reference from a non-cell array object.

Error in plot_graph>sub_mdot_write (line 169)
str{1} = sprintf('digraph %s_calls{',opt.names{1});

Error in plot_graph (line 48)
opt = sub_mdot_write(opt);

Moreover is there some way I can add signs to the arrows? liked signed digraphs, + and -?

Bruce - thanks for the feedback. I have updated the submission with your suggested change. I have confirmed this worked under windows7/2012B.

If anyone else is having problems getting this to run, please get in touch. I'm especially eager to hear if it works under unix.


On Windows, line 202 (in sub_mwdot_call) needs fixing. It needs a '"' after the open square bracket and a " after the ' before -Tplain, otherwise it complains bitterly.

Other than that, so far I'm very impressed.

Richard Ruff

@Richard Ruff.
Thanks for your comment. I have added a bugfix that correctly handles built-in functions. Hope this fixes the issues you are having.

the function actually uses mlintmex, so it must have an m-file to examine. It will use the "which" command to determine which file it should examine.

For example:
will give you a plot of the 22 subroutines in the file plot_subfun.m.

will tell you there are no subroutines, because the file plot.m is just a script. My function isn't clever enough to realise that plot.m is also a wrapper for a built-in function.

Richard Ruff

Christopher - Do you have examples to run? Every file I have tried has failed. I haven't investigated in detail, but appears this requires the functions be executed, so the user must replace foo in your comments with a full function call syntax. Is that correct? A few examples will help the user understand the requirements to run this.

Christopher Pedersen

Johannes - latest version I believe adresses your comments by adding more options for hiding subroutines.

Johannes Korsawe

I change my rating to 5 stars, as my proposed improvement is nearly handled with the options, which i had overlooked at first sight.

Nevertheless, my suggestion would be a nice minor improvement.

Johannes Korsawe

This submission is pretty cool.

Just one star missing to encourage the author to improve the submission in the following context:

For large projects, the map may become confusing.
How about declaring levels of detail for substructuring in general and maybe specific to functionnames? It would be great if you could declare an additional list of functionnames, telling plot_subroutines, that "under"/"beneath" these functions, no subfunctions shall be plotted. So the plot could be purified from all those nasty "small" functions.


Christopher Pedersen

Marta - thanks for the feedback. I think the problem you are having is that 'ScriptAtlas.m' is a script, rather than a function, so it doesn't have any subroutines !

I have updated plot_subroutines to handle this situation - it now tells you that there are no subroutines, and returns an empty result.


This id a great idea. Shame there are several bugs in the code that make it unusable.

E.g. running:

Reference to non-existent field 'name'.
Error in plot_subroutines>sub_calls (line 108)
ext = ~ismember(,;
Error in plot_subroutines (line 22)
data = sub_calls(data);

If you fix this error, another one about other non-existing fields appears...

Looking forward to using the code once you have fixed these.


MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!