0

I want to calculate Nodal clustering coefficient distribution with a connectivity matrix But when I operate this code, it return nothing. What is the problem? Can't I use function plot like that?

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

2 Answers 2

1

Each call to plot will erase the previously plotted data, unless you write

hold on

before the loop (or unless you edit the axes properties).

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
Sign up to request clarification or add additional context in comments.

1 Comment

See also hold all, hich automatically changes line color for each graph
0

Your code is probably going to run better if you first gather all the data points, and only plot them in the end. Here is how this can be done:

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.