separate lines on 2d graph using two separate pairs of vectors
Afficher commentaires plus anciens
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!
Réponses (2)
Fangjun Jiang
le 26 Sep 2011
line([x1,m1],[y1,n1]);
hold on;
line([x2,m2],[y2,n2]);
2 commentaires
Grzegorz Knor
le 26 Sep 2011
hold on is unnecessary in this case.
Walter Roberson
le 26 Sep 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
le 26 Sep 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 commentaires
Hershy
le 26 Sep 2011
Walter Roberson
le 26 Sep 2011
line( reshape([x(:),m(:),nan(numel(x),1)].',1,[]), ...
reshape([y(:),n(:),nan(numel(x),1)].',1,[]) );
Hershy
le 26 Sep 2011
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!