我想用连接矩阵计算Nodal聚类系数分布 但是当我操作这段代码时,它什么也没有返回。问题是什么? 我不能像那样使用功能图吗?
cm = [0,1,1,1,0;1,0,0,1,0;0,1,0,0,0;1,0,0,0,0;0,0,0,0,0];
bg = biograph(cm);
for i = 1:5
intNodes = getrelatives(bg.nodes(i));
num = numel(intNodes);
plot(i,num);
end
答案 0 :(得分:1)
除非您编写
,否则每次调用绘图都将删除先前绘制的数据 hold on
(或者除非你编辑轴属性)。
cm = [0,1,1,1,0;1,0,0,1,0;0,1,0,0,0;1,0,0,0,0;0,0,0,0,0];
bg = biograph(cm);
figure %# create new figure
hold on %# create axes, make sure that plots get added instead of replaced
for i = 1:5
intNodes = getrelatives(bg.nodes(i));
num = numel(intNodes);
plot(i,num);
end
答案 1 :(得分:0)
如果您首先收集所有数据点,您的代码可能会运行得更好,并且最终只绘制它们。以下是如何做到这一点:
cm = [0,1,1,1,0;1,0,0,1,0;0,1,0,0,0;1,0,0,0,0;0,0,0,0,0];
bg = biograph(cm);
plotData = NaN(5,1)
for i = 1:5
intNodes = getrelatives(bg.nodes(i));
num = numel(intNodes);
plotData(i)=num
end
plot(1:5,plotData)