File Exchange

image thumbnail

graphViz4Matlab

version 1.3 (274 KB) by

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

4.54545
12 Ratings

24 Downloads

Updated

View License

This package, (formerly called Graphlayout) is now maintained here:
http://code.google.com/p/graphviz4matlab/

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 https://github.com/graphviz4matlab/graphviz4matlab/

mmeyer89

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

function readLayout(obj)
       % Parse the layout.dot file for the graphViz node locations and
       % dimensions.
            fid = fopen(obj.layoutFile,'r');
            text = textscan(fid,'%s','delimiter','\n');
            fclose(fid);
            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
                    
            obj.scaleLocations(locations,dims);
       end

Pull request is open (https://github.com/graphviz4matlab/graphviz4matlab/pull/7)

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)
            obj.drawNode();

Error in graphViz4Matlab/displayGraph (line 525)
               node.draw(obj.ax);

Error in graphViz4Matlab/draw (line 161)
           obj.displayGraph();

Error in graphViz4Matlab (line 150)
            obj.draw();

Error in graphViz4MatlabDEMO1 (line 6)
graphViz4Matlab('-adjMat',adj,'-nodeLabels',names,'-layout',Treelayout,'-nodeColors',nodeColors,'-edgeColors',
edgeColors);

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 layout.dot file for the graphViz node locations and
       % dimensions.
            fid = fopen(obj.layoutFile,'r');
            text = textscan(fid,'%s','delimiter','\n');
            fclose(fid);
            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;
            obj.scaleLocations(locations,dims);
       end

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.
Thanks.

Lie Tome

Works wonderfully well.

haya

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

Updates

1.3

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

1.2

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

1.1

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

MATLAB Release
MATLAB 7.6 (R2008a)
Acknowledgements

Inspired: A patch for graphViz4Matlab toolbox

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

» Watch video