I'm trying to implement an algorithm for prediction of missing nodes using Matlab. But, there are some errors in my coding , Could anyone please correct my code?
1 次查看(过去 30 天)
显示 更早的评论
clc;
edges = dlmread('twitnet.csv');
edges(all(edges == 0, 2), :) = [];
[uedges, ~, erow] = unique(edges.', 'stable'); %transpose and stable to give the same output as graph
X = full(sparse(erow(1:2:end), erow(2:2:end), 1, numel(uedges), numel(uedges)));
X = X + X.';
CDcalculation(CD); %consistency degree
* error after this *
Thanks in advance
0 个评论
回答(2 个)
Walter Roberson
2017-3-30
Consider your line
[j,k]=CN;
You are within a "for j" loop, so you would be overwriting the loop control variable "j". Overwriting a loop control variable is almost always a mistake.
You are writing to multiple outputs. The only way that could be valid would be if CN were a function (whose code you do not show.) That would be consistent with the fact that you have not defined CN at that point.
But on the next line you have
CN=find(X(j,1)==X(j,k)); %consistency calculation
which assigns to CN as a variable. If you managed to execute that line (because you had a function named CN with multiple outputs) then your next loop through would have to fail, when CN had become a numeric variable, as it is not possible to assign a numeric variable to multiple outputs.
2 个评论
Guillaume
2017-3-30
Note: the only part of your code that works is actually the one I wrote in answer. After that, nothing makes sense. In addition to the issues that Walter pointed out we start with:
for j = X(:,1) : X(:, :)
I have absolutely no idea what you're meaning to do with that line, but it's certainly not going to do what you want. You're passing vectors and matrices as the boundaries of the loop, matlab ignores these and only use the first element. So that line is equivalent to:
for j = X(1,1):X(1,1)
So the j loop will only have one step.
Similarly, your k loop is equivalent to:
for k = X(1,2):X(1,1)
Now since X is an adjacency matrix with only 0 and 1, that loop will either never execute or execute once. Hardly worth a loop.
Then we have the [i,j]=CN that Walter mentioned. That also makes no sense.
I have no idea what you're trying to do, but you should seriously consider learning more about matlab syntax before proceeding.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!