我正在尝试使用单词邻接数据构建网络图。但我收到错误“目标必须是节点索引的密集双数组”。以下是我的代码:
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))
时,它会抛出错误。