Error when running G= graph(s,t) in matlab
23 views (last 30 days)
Show older comments
I want to calculate L = laplacian(G) from a graph dataset. I imported the dataset, from here , which contains two columns as shown below:
# Nodes: 3997962 Edges: 34681189
# FromNodeId ToNodeId
0 1
0 2
0 31
0 73
0 80
0 113619
0 2468556
0 2823829
0 2823833
0 2846857
0 2947898
0 3011654
0 3701688
0 3849377
0 4036524
0 4036525
0 4036527
0 4036529
0 4036531
0 4036533
0 4036534
0 4036536
0 4036537
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
To do so, I need to find G first so I use G = graph(FromNodeId, ToNodeId). When I did that, I got this error:
>> G = graph(fromNodeId,toNodeId)
Error using matlab.internal.graph.MLGraph
Source must be a dense double array of node indices.
Error in matlab.internal.graph.constructFromEdgeList (line 125)
G = underlyingCtor(double(s), double(t), totalNodes);
Error in graph (line 264)
matlab.internal.graph.constructFromEdgeList(...
I don't know why! Can I get a solution of that? Thank you.
Accepted Answer
More Answers (1)
lol
on 10 Nov 2021
THIS IS MY CODE:
filename = 'TABLA_AF1';
s = xlsread(filename,'A2:A25');
t = xlsread(filename,'B2:B25');
weights = xlsread(filename,'C2:C25');
G = graph(s,t,weights);
p = plot(G,'EdgeLabel',G.Edges.Weight);
[T,pred] = minspantree(G);
highlight(p,T)
AND THIS IS MY BASE DATA:
Nodo Inicial Nodo Final Distancia
A B 2
A E 16
A C 3
C F 3
C I 12
F E 7
F I 9
F H 6
I H 14
E H 2
E G 4
B E 8
B D 11
D E 2
D G 5
D J 7
G J 1
G L 6
H G 3
J L 12
H L 17
I K 7
H K 9
K L 17
AND I GET THIS ERROR:
Error using matlab.internal.graph.constructFromEdgeList (line 249)
Weight must have as many elements as edge list or be a scalar.
Can you tell me why please?
12 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!