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

JAYANTH BHIMAVARAPU
JAYANTH BHIMAVARAPU 2018년 6월 29일
Can you share the URV.txt file too with this post??
Guillaume
Guillaume 2018년 6월 29일
편집: Guillaume 2018년 6월 29일
It would be very helpful if you attached URV.txt to your question.
Also, can you post the whole text of the error message. Everything in red.
Chinenye Ezeh
Chinenye Ezeh 2018년 6월 29일
Actually, I am working with very large datasets from different networks. So, I need a means to access them through text files.
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in graph>testadjmatrix (line 713) mOut(mOut == 0) = varargin{1};
Error in graph (line 281) [E,N,eps] = fromweightedadjmatrix(testadjmatrix(varargin{1},emptyValue),emptyValue);
Error in * (line 16) G=graph(A{1}, A{2});

댓글을 달려면 로그인하십시오.

 채택된 답변

Steven Lord
Steven Lord 2018년 6월 29일

0 개 추천

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

Chinenye Ezeh
Chinenye Ezeh 2018년 6월 29일
편집: Chinenye Ezeh 2018년 6월 29일
The output is shown below:
s1 =
5449 1
c1 =
'double'
isc1 =
logical
0
s2 =
5449 1
c2 =
'double'
isc2 =
logical
0
I just looked at the graph function included in release R2017a. The error message in your image refers to line 281 of the graph function, but that code doesn't appear in the graph function in that release (either on line 281 or any other, according to the Find dialog.) Line 281 of the graph function included in MATLAB is "end".
Can you show the version of MATLAB you're using?
version
Can you show which graph function you're calling?
which -all graph
If it shows something other than the graph constructor in the toolbox\matlab\graphfun directory under matlabroot, you'll need to either:
  1. rename or remove that function so you can call the graph function included in MATLAB or
  2. use input arguments that satisfy that function's requirements, which may be different from those of the graph function included in MATLAB.
version
ans =
'9.2.0.538062 (R2017a)'
Chinenye Ezeh
Chinenye Ezeh 2018년 6월 30일
편집: Chinenye Ezeh 2018년 6월 30일
which -all graph
E:\matlab\bin\torsche-master\torsche-master\scheduling\@graph\graph.m % graph constructor E:\matlab\toolbox\matlab\graphfun\@graph\graph.m % Shadowed graph constructor
Chinenye Ezeh
Chinenye Ezeh 2018년 6월 30일
It works well now. I figured out there had been conflict of graph functions. I deleted the first folder to enable Matlab inbuilt graph function work properly. A big thanks to Steven Lord and every other person who helped out.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2018년 6월 29일

댓글:

2018년 6월 30일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by