-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfind_graph.m
More file actions
29 lines (28 loc) · 793 Bytes
/
Copy pathfind_graph.m
File metadata and controls
29 lines (28 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function graph=find_graph(gmlstruct)
% graph=find_graph(gmlstruct) finds graph in gmlstruct
%
% Recursively iterates through gmlstruct until it finds the graph and
% returns it. If no graph is found, returns empty array.
% Version: 2.0
% Date: Thu 5 Jul 2018 14:15:23 CEST
% Author: Lucas Jeub
% Email: lucasjeub@gmail.com
graph=[];
if isstruct(gmlstruct)
if isfield(gmlstruct,'node')
% gmlstruct is already a graph
graph=gmlstruct;
elseif~isfield(gmlstruct,'graph')
% no graph at top level
fields=fieldnames(gmlstruct);
i=1;
while isempty(graph)&&i<=length(fields)
graph=find_graph(gmlstruct.(fields{i}));
i=i+1;
end
else
% graph at top level
graph=gmlstruct.graph;
end
end
end