Error in Network Graph
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chinenye Ezeh
il 29 Giu 2018
Commentato: Chinenye Ezeh
il 30 Giu 2018
I tried to generate a graph after reading some values from a txt file. But I get the error message "In an assignment A(:) = B, the number of elements in A and B must be the same. " My code is shown below:
fid = fopen('URV.txt','rt');
A = textscan(fid, '%f%f', 'MultipleDelimsAsOne',true, 'Delimiter','[;', 'HeaderLines',2);
fclose(fid);
G=graph(A{1}, A{2});
I do not know what the actual issue is as I have looked at other codes from Mathworks which seem correct. I have tried a couple other formats but nothing seems to work. What am I doing wrong? Any help will be appreciated. Thanks
3 Commenti
Risposta accettata
Steven Lord
il 29 Giu 2018
From the documentation for the graph function, "G = graph(s,t) specifies graph edges (s,t) in node pairs. s and t can be numeric, character vectors, or cell arrays of character vectors with the same number of elements."
The key requirement that I suspect your data fails to satisfy is the "same number of elements" section. To confirm this and also to check the other requirements while we're at it, immediately before the line where you try to construct the graph run these lines of code and show us what they display.
s1 = size(A{1})
c1 = class(A{1})
isc1 = iscellstr(A{1})
s2 = size(A{2})
c2 = class(A{2})
isc2 = iscellstr(A{2})
5 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Graph and Network Algorithms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
