1

I try to create a network simulation using MATLAB. I want to display all nodes and cluster heads and the connection between those two like the picture below.

enter image description here

The problem is I can't draw the lines between all cluster heads (dotted blue) to base stations (red cross). Below is the code I tried:

subplot(2,2,3);
for i=1:numel(MCH(10,:))
    if(isfield(MCH{10,i},'x'))
        MCHX = [MCHX C{10,i}.x];
        MCHY = [MCHY C{10,i}.y];
        plot([MCH{10,i}.x sink.x],[MCH{10,i}.y sink.y],'-black');
    end
end

It seems like plot only draws the last line.

Any idea how to solve this problem? I appreciate any help.

1 Answer 1

2

Use hold on to retain everything you draw in the plot:

subplot(2,2,3);
hold on;
for i=1:numel(MCH(10,:))
    if(isfield(MCH{10,i},'x'))
        MCHX = [MCHX C{10,i}.x];
        MCHY = [MCHY C{10,i}.y];
        plot([MCH{10,i}.x sink.x],[MCH{10,i}.y sink.y],'-black');
    end
end
Sign up to request clarification or add additional context in comments.

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.