필터 지우기
필터 지우기

I am a beginner in matlab. So, Could anyone please help me to create an adjacency matrix based on this attached dataset? This set consists of nodes and edges, so I want adjacency matrix where 1 represents connected nodes otherwise 0.

조회 수: 1 (최근 30일)
Thanks
  댓글 수: 4
Guillaume
Guillaume 2017년 3월 24일
We know what an adjacency matrix is. Rik was asking you to demonstrate that you'd made some effort towards getting your answer, particularly if it's homework.
SUNANNA S S
SUNANNA S S 2017년 3월 27일
편집: Guillaume 2017년 3월 27일
Sorry for the mistake Sir. This is the code that I tried, but this has so many problems.Please help.
function osnToBIS()
clc;
A=csvread('twitnet');
B=unique(A);
m=size(B);
for i=1:size(B)
[r,c]=find(B(i)==A);
for j=1:size(c)
if c(j)==1
c(j)=2;
else
c(j)=1;
end
end
N=A(r,c);
radj=find(adj(:,1)==B);
cadj=find(adj(1,:)==unique(N));
adj(radj,cadj);
end
The error in this program is:
Undefined variable adj.
Error in osnToBIS (line 16)
radj=find(adj(:,1)==B);

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2017년 3월 21일
Once you've imported your data, the graph and adjacency function are pretty much all you need . However, considering that you've got 892 nodes, that adjacency matrix is going to be big and imposible to visualise.
Two issues are that your text file contains a lot of empty entries (just ,) which needs to be filtered out, and that if you give numeric nodes to graph it expects these to be numbered from 1 to numberofnoes. You can either converts the numbers to char arrays or renumber the nodes(with unique).
edges = dlmread('twitnet.csv');
edges(all(edges == 0, 2), :) = [];
edges = arrayfun(@num2str, edges, 'UniformOutput', false);
g = graph(edges(:, 1), edges(:, 2));
plot(g);
adjm = full(adjacency(g))
  댓글 수: 4
Guillaume
Guillaume 2017년 3월 24일
You really should move to a version of matlab a bit more recent. You're missing out on lots of useful graph functions (in particular, the above will give you a very nice plot of your graph).
Without the nice graph functions, you can still build the adjacency matrix with a bit more effort:
edges = dlmread('twitnet.csv');
edges(all(edges == 0, 2), :) = [];
[uedges, ~, erow] = unique(edges.', 'stable'); %transpose and stable to give the same output as graph
adjm2 = full(sparse(erow(1:2:end), erow(2:2:end), 1, numel(uedges), numel(uedges)));
adjm2 = adjm2 + adjm2.';

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by