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

回答 (2 件)

Walter Roberson
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 件のコメント
SUNANNA S S
SUNANNA S S 2017 年 3 月 30 日
Thank you for your reply Sir. In this, actually I want to calculate CN(j,k) = find(X(i,j)==X(i,k)), but I don't know how to do it in matlab. Actually,CN is the consistency of jth column with all other k columns. So, I'm fully confused about how to do it. Please help.
SUNANNA S S
SUNANNA S S 2017 年 3 月 30 日
編集済み: Walter Roberson 2017 年 3 月 30 日
As per your guidance, I calculate consistency(CN) and consistency degree(CD) as separate functions, but still errors remain.Please check my code Sir.
function CNcalculation()
for j=X(:,1): X(:,:)
for i=1:length(X)
if find(X(i,j)==0);
for k=X(:,2):X(:,:)
CN=find(X(i,j)==X(i,k));
end
end
end
end
CNcalculation(CN);
%for CD calculation
function CDcalculation()
CNcalculation(CN);%consistency calculation
for j=X(:,1): X(:,:)
U(j)=X(sum(:,X == 1) ); %no: of linked nodes of jth column
CD=max(CN/U(j));%consistency degree calculation
end
CDcalculation(CD);

サインインしてコメントする。


Guillaume
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.
  1 件のコメント
SUNANNA S S
SUNANNA S S 2017 年 3 月 30 日
Sir,actually I want to find the consistency of each columns with all other columns. So that I want to assign j pointer to first column and k to all other columns, that's why I use this loop,but I cannot achieve the result that I expected,as you said. I don't know how to do it and I had tried many ways by seeing some tutorials,but that's not I want. Please help.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by