separate lines on 2d graph using two separate pairs of vectors
Mostrar comentarios más antiguos
How do draw separate lines, one from x1, y1 to m1, n1, another from x2, y2 to m2, n2 and so on...?
Thanks so much!
Respuestas (2)
Fangjun Jiang
el 26 de Sept. de 2011
line([x1,m1],[y1,n1]);
hold on;
line([x2,m2],[y2,n2]);
2 comentarios
Grzegorz Knor
el 26 de Sept. de 2011
hold on is unnecessary in this case.
Walter Roberson
el 26 de Sept. de 2011
Correct, Grzegorz.
For future reference by other people reading this: line() always adds to the current graphics, no matter what the hold state is. plot(), however, pays attention to the hold state.
Grzegorz Knor
el 26 de Sept. de 2011
% generate some data
x1 = rand();
y1 = rand();
m1 = rand();
n1 = rand();
x2 = rand();
y2 = rand();
m2 = rand();
n2 = rand();
% option one
figure
line([x1 m1],[y1 n1],'color','b')
line([x2 m2],[y2 n2],'color',[0 0.498 0])
% option 2
figure
plot([x1 m1],[y1 n1],[x2 m2],[y2 n2])
% option 3
figure
hold all
plot([x1 m1],[y1 n1])
plot([x2 m2],[y2 n2])
3 comentarios
Hershy
el 26 de Sept. de 2011
Walter Roberson
el 26 de Sept. de 2011
line( reshape([x(:),m(:),nan(numel(x),1)].',1,[]), ...
reshape([y(:),n(:),nan(numel(x),1)].',1,[]) );
Hershy
el 26 de Sept. de 2011
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!