我正在尝试使用word adjacency构建一个网络图数据。但我收到错误“目标必须是节点索引的密集双数组”。以下是我的代码:
fileName = 'adjnoun.gml';
inputfile = fopen(fileName);
A=[];
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'); %get number from string
if length(nums)
if l==1
l=0;
A(k,2)=str2num(nums{1});
k=k+1;
continue;
end
A(k,1)=str2num(nums{1});
l=1;
else
l=0;
continue;
end
end
A= sort(A);
g = graph(A(:,1),A(:,2));
A 是 425X2 双矩阵。当我尝试创建图形 g = graph(A(:,1),A(:,2))
时,它抛出错误。
最佳答案
如果源数组或目标数组中有 0,Matlab 的 graph(s, t)
函数将显示该错误。换句话说,如果 A(:, 2)
包含任何零,Matlab 将失败并显示错误。你可以:
我。将“1”添加到所有值中:A=A+1
关于matlab - 目标必须是节点索引的密集 double 组。怎么解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075759/