How to draw bunch of line segments?

48 views (last 30 days)
Mr M.
Mr M. on 22 Aug 2017
Answered: Jan on 22 Aug 2017
I would like to draw [x1 x2],[y1 y2] line segments, and I have data in the form X1(i) = x1 etc. and i=1:1000; Is it possible to draw the lines without a for cycle?

Accepted Answer

Jan
Jan on 22 Aug 2017
You can. But what is the wanted result?
X1 = rand(1, 10);
X2 = rand(1, 10);
Y1 = rand(1, 10);
Y2 = rand(1, 10);
subplot(1,2,1)
plot([X1; X2], [Y1; Y2]) % A bunch of separate lines
subplot(1,2,2)
plot([X1; X2].', [Y1; Y2].') % Two polygones

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 22 Aug 2017
x=1:10;
y=rand(size(x));
line(x,y);

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!