目标必须是密集的双节点索引数组。怎么解决? [英] Target must be a dense double array of node indices. How to Solve?
问题描述
我正在尝试使用数据构建网络图。但是我得到错误目标必须是密集的双节点索引数组。以下是我的代码:
fileName ='adjnoun.gml';
inputfile = fopen(fileName);
A = [];
l = 0;
k = 1;
while 1
%从输入文件中获取一行
tline = fgetl(inputfile);
如果文件结束,退出
if〜ischar(tline)
break
end
$ b nums = regexp(tline,'\\ \\d +, '匹配'); %从字符串获得数字
如果长度(数量)
如果l == 1
l = 0;
A(k,2)= str2num(nums {1});
k = k + 1;
继续;
end
A(k,1)= str2num(nums {1});
l = 1;
else
l = 0;
继续;
end
end
A = sort(A);
g = graph(A(:,1),A(:,2));
A是425X2的双重矩阵。当我试图创建图 g = graph(A(:,1),A(:2))
时,它会抛出错误。
如果你有0的话,Matlab的图形(s,t)
在您的源或目标阵列中。换句话说,如果 A(:, 2)
包含任何零,Matlab将会失败并显示错误。你可以:
i。 ii。将所有值加上1: A = A + 1
I am trying to build a network graph with word adjacency data. But I am getting the error "Target must be a dense double array of node indices". Following is my code:
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 is 425X2 double matrix. When I am trying to create the graph g = graph(A(:,1),A(:,2))
, it is throwing the error.
Matlab's graph(s, t)
function will display that error if you have 0's in your source or target arrays. In other words, if A(:, 2)
contains any zeros, Matlab will fail with the displayed error. You could:
i. Add "1" to all of your values with: A=A+1
ii. Modify your original graph to produce a .gml output without zeros.
这篇关于目标必须是密集的双节点索引数组。怎么解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!