MATLAB: Error in plotting graph

graph

Hi community, please I'm try to plot a graph from a gml file containing data. I'm getting an error when i try to create the graph. The error reads "Error using matlab.internal.graph.MLGraph. Target must be a dense double array of positive integer node indices."
This is my code.
%Extracting edges from gml file graph
fileName = 'power.gml';
inputfile = fopen(fileName);
Edges=[];
l=0;
k=1;
while 1
% Get a line from the input file
tline = fgetl(inputfile);
% Quit if end of file
if ~ischar(tline)
break
end
nums = regexp(tline,'\d+','match');
if length(nums)
if l==1
l=0;
Edges(k,2)=str2num(nums{1});
k=k+1;
continue;
end
Edges(k,1)=str2num(nums{1});
l=1;
else
l=0;
continue;
end
if Edges(:,2)== 0
Edges (:,2) = 1;
end
end
Edges = Edges+1;
G = graph(Edges(:,1), Edges(:,2)); % create a graph from A
figure % visualize the graph
plot(G);

Best Answer

Got it working now, did some editing..
%Extracting edges from gml file graph
fileName = 'power.gml';
inputfile = fopen(fileName);
Edges=[];
l=0;
k=1;
while 1
% Get a line from the input file
tline = fgetl(inputfile);
% Quit if end of file
if ~ischar(tline)
break
end
nums = regexp(tline,'\d+','match');
if length(nums)
if l==1
l=3; % the 0 here was the problem...
Edges(k,2)=str2num(nums{1});
k=k+1;
continue;
end
Edges(k,1)=str2num(nums{1});
l=1;
else
l=0;
continue;
end
end
Edges = Edges+1;
G = graph(Edges(:,1), Edges(:,2)); % create a graph from A
figure % visualize the graph
plot(G);