separate lines on 2d graph using two separate pairs of vectors
Show older comments
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!
Answers (2)
Fangjun Jiang
on 26 Sep 2011
line([x1,m1],[y1,n1]);
hold on;
line([x2,m2],[y2,n2]);
2 Comments
Grzegorz Knor
on 26 Sep 2011
hold on is unnecessary in this case.
Walter Roberson
on 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
on 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 Comments
Hershy
on 26 Sep 2011
Walter Roberson
on 26 Sep 2011
line( reshape([x(:),m(:),nan(numel(x),1)].',1,[]), ...
reshape([y(:),n(:),nan(numel(x),1)].',1,[]) );
Hershy
on 26 Sep 2011
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!