How to connect the multi scatter?

I want to connect pone in a line follow the for loop, the same for ptwo. And suppose that I have 2 first points. This is my code:
for p=1:10
pone=randi(10,1);
ptwo=randi(10,1);
plot(p,pone,'r.',p,ptwo,'c*','MarkerSize',10)
hold on
axis([0 5 0 20])
end
hold off

 Respuesta aceptada

Star Strider
Star Strider el 20 de Mayo de 2019
I am not certain what reault you want.
Try this:
p=1:10;
pone=randi(10,1,numel(p));
ptwo=randi(10,1,numel(p));
plot(p,pone,'r.-',p,ptwo,'c*-','MarkerSize',10)
axis([0 5 0 20])

4 comentarios

Hang Vu
Hang Vu el 20 de Mayo de 2019
That's the result I want, but is there any way to put in for loop?
You can only draw a line between two points, so in every iteration of the looop, you would have to connect the points. You are creating one point at a time, so connecting them would not be possible.
This is the best I can create that uses a loop:
poneprev=3;
ptwoprev=4;
pprev = 0;
hold all
for p=1:10
pone=randi(10,1);
ptwo=randi(10,1);
plot(p,pone,'r.',p,ptwo,'c*','MarkerSize',10)
line([pprev p],[poneprev pone],'Color','r')
line([pprev,p],[ptwoprev ptwo],'Color','c')
poneprev = pone;
ptwoprev = ptwo;
pprev = p;
axis([0 5 0 20])
end
hold off
I obviously do not reccommend the loop approach.
Hang Vu
Hang Vu el 21 de Mayo de 2019
Thank you so much!^^
Star Strider
Star Strider el 21 de Mayo de 2019
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 20 de Mayo de 2019

Comentada:

el 21 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by