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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by