File Exchange

image thumbnail


version 1.3 (274 KB) by

Display a directed or undirected graph in a Matlab figure window.

12 Ratings



View License

This package, (formerly called Graphlayout) is now maintained here:

Please see this site the for the latest downloads and documentation.

Comments and Ratings (15)

Tom Hawkins

The Google Code link is no longer current, the package is now maintained at


In the current version there is a bug in readlayout(). I wrote a new regexp based version of it.

function readLayout(obj)
       % Parse the file for the graphViz node locations and
       % dimensions.
            fid = fopen(obj.layoutFile,'r');
            text = textscan(fid,'%s','delimiter','\n');
            text = text{:};
            % Read Graphviz dimensions
            dim_text = text{strncmp(text, 'graph [bb="', 11)};
            dims = sscanf(dim_text(12:end),'%f,')';
            % Read the position of nodes
            location_tokens = regexp(horzcat(text{:}), ';([0-9]+)\s+\[[^\]]*pos="(-?[0-9\.]+),(-?[0-9\.]+)"', 'tokens');
            location_tokens = vertcat(location_tokens{:});
            % Convert to numeric values
            node_idx = sscanf(strjoin(location_tokens(:,1)), '%d');
            locations = reshape(sscanf(strjoin(location_tokens(:,2:3)), '%f'),[],2);
            locations(node_idx,:) = locations; % reorder based on id

Pull request is open (

Shusen Zhang

When I run the demos, the program is getting some error related with display a rectangle shape. Is there any solutions to that?
Error using rectangle
There is no DisplayName property on the Rectangle class.

Error in graphViz4MatlabNode/drawNode (line 193)
            obj.rechandle = rectangle(...

Error in graphViz4MatlabNode/draw (line 81)

Error in graphViz4Matlab/displayGraph (line 525)

Error in graphViz4Matlab/draw (line 161)

Error in graphViz4Matlab (line 150)

Error in graphViz4MatlabDEMO1 (line 6)

Jack Ie

Jack Ie

display this error only:
'neato' is not recognized as an internal or external command,
operable program or batch file.

There is a bug, in that the node id's are assumed to be in linear order in the resulting dot file.
To fix this replace the following function in Graphvizlayout.m
function readLayout(obj)
       % Parse the file for the graphViz node locations and
       % dimensions.
            fid = fopen(obj.layoutFile,'r');
            text = textscan(fid,'%s','delimiter','\n');
            text = text{:};
            [start,dims] = strtok(text{cellfun(@(x)~isempty(x),strfind(text,'graph [bb="'))},'"');
            dims = textscan(strtok(dims,'"'),'%n','delimiter',',');
            dims = dims{:}';
            text(cellfun(@(x)~isempty(x),strfind(text,' -> ')))=[]; % delete edge info, we don't need it
            node_id_text = text(cellfun(@(x)~isempty(x),strfind(text,'height'))); % keep only positions
            node_id = str2double(strtok(node_id_text,' '));
            text(cellfun(@(x)isempty(x),strfind(text,'pos')))=[]; % keep only positions
            [start,remaining] = strtok(text,'"');
            [locations,remaining] = strtok(remaining,'"');
            locations = cellfun(@(str)textscan(str,'%n','delimiter',','),locations,'UniformOutput',false);
            locations = [locations{:}];
            locations = [locations{:}]';
            % reorder based on id
            locations(node_id,:) = locations;

I do know if this fix works in all scenarios, but it appears to work for all of mine. Without the fix, the resulting images aren't very pretty.

Peter Merk

Great tool! Very easy to use and nice graphics. The only thing missing is the possibility to name the edges.

Brilliant tool. Easy to use, very nice GUI and good idea.
Well done.

Lie Tome

Works wonderfully well.


haya (view profile)

Hello, I'm trying to use graphViz4Matlab
I read the comments in the code and saw I can give only my adj matrix as input. I entered a 99x99 matrix and got the follow error:??? Error: File: C:\MATLAB7\work\Wlan-matrix2\graphViz4Matlab.m Line: 86 Column: 26
The expression to the left of the equals sign is not a valid target for an assignment.
In the code the line itself is:
properties(GetAccess = 'public', SetAccess = 'private')
can you please tell me what i did wrong, I expected a simple line like this wont have any problem
thank you

Julian Xue

Works great, but takes forever for large graphs (>1000 nodes). Is there a faster version available?

Shicai Yang

it looks great~

Daniel Zoran



Fixed a small bug in the setupPath() function of the util directory. Output argument was not always getting set.


Now automatically adds graphViz to your system path, from within Matlab, (if running windows).


Various bug fixes, as well as an additional option to color the edges.

MATLAB Release
MATLAB 7.6 (R2008a)

Inspired: A patch for graphViz4Matlab toolbox

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

» Watch video