目标必须是节点索引的密集双精度数组。怎么解决?

Target must be a dense double array of node indices. How to Solve?

我正在尝试使用 word adjacency 数据构建网络图。但是我收到错误 "Target must be a dense double array of node indices"。以下是我的代码:

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

二。修改原始图形以生成不带零的 .gml 输出。