Skip to content

Commit 9fc869b

Browse files
committed
graph and digraph is now working
1 parent 9d0fd4a commit 9fc869b

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

jdataencode.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
function jdata=jdencode(data, varargin)
1+
function jdata=jdataencode(data, varargin)
22
%
3-
% jdata=jdencode(data)
3+
% jdata=jdataencode(data)
44
% or
5-
% jdata=jdencode(data, options)
6-
% jdata=jdencode(data, 'Param1',value1, 'Param2',value2,...)
5+
% jdata=jdataencode(data, options)
6+
% jdata=jdataencode(data, 'Param1',value1, 'Param2',value2,...)
77
%
88
% Serialize a MATLAB struct or cell array into a JData-compliant
99
% structure as defined in the JData spec: http://github.com/fangq/jdata
@@ -19,7 +19,7 @@
1919
% total element count is larger than this number.
2020
%
2121
% example:
22-
% jd=jdencode(struct('a',rand(5)+1i*rand(5),'b',[],'c',sparse(5,5)))
22+
% jd=jdataencode(struct('a',rand(5)+1i*rand(5),'b',[],'c',sparse(5,5)))
2323
%
2424
% license:
2525
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
@@ -55,7 +55,7 @@
5555
newitem=mat2jd(item,varargin{:});
5656
elseif(isa(item,'table'))
5757
newitem=table2jd(item,varargin{:});
58-
elseif(isa(item,'digraph'))
58+
elseif(isa(item,'digraph') || isa(item,'graph'))
5959
newitem=graph2jd(item,varargin{:});
6060
else
6161
newitem=any2jd(item,varargin{:});
@@ -164,13 +164,19 @@
164164
function newitem=graph2jd(item,varargin)
165165
newitem=struct;
166166
nodedata=table2struct(item.Nodes);
167-
if(any(ismember(G.Edges.Properties.VariableNames,'Name')))
167+
if(isfield(nodedata,'Name'))
168168
nodedata=rmfield(nodedata,'Name');
169-
newitem(N_('_GraphNodes_'))=containers.Map(item.Nodes.Name,num2cell(nodedata),'uniformValues',false);
169+
newitem.(N_('_GraphNodes_'))=containers.Map(item.Nodes.Name,num2cell(nodedata),'uniformValues',false);
170170
else
171-
newitem(N_('_GraphNodes_'))=containers.Map(1:max(item.Edges.EndNodes(:)),num2cell(nodedata),'uniformValues',false);
171+
newitem.(N_('_GraphNodes_'))=containers.Map(1:max(item.Edges.EndNodes(:)),num2cell(nodedata),'uniformValues',false);
172172
end
173-
newitem(N_('_GraphEdges_'))=num2cell(table2cell(item.Edges),2);
173+
edgenodes=item.Edges.EndNodes;
174+
edgedata=table2struct(item.Edges);
175+
if(isfield(edgedata,'EndNodes'))
176+
edgedata=rmfield(edgedata,'EndNodes');
177+
end
178+
edgenodes(:,3)=num2cell(edgedata);
179+
newitem.(N_('_GraphEdges_'))=edgenodes;
174180

175181
%%-------------------------------------------------------------------------
176182
function newname=N_(name,varargin)

0 commit comments

Comments
 (0)