Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
need help in plotting lines between points

Subject: need help in plotting lines between points

From: Faisal Ahmed

Date: 17 Jul, 2010 03:42:05

Message: 1 of 5

I need help in plotting lines between points.
Suppose, I start with creating 6 random points-

x = rand(6,1);
y = rand(6,1);

So my points are (x(1),y(1)), (x(2),y(2)), (x(3),y(3)), (x(4),y(4)), (x(5),y(5)), (x(6),y(6))

Now I want to draw straight lines between the points 1 & 5, 2 & 6, 3 & 4
and plot them in a single diagram. So I get 3 straight lines.

Any help would be highly appreciated.

Subject: need help in plotting lines between points

From: zac

Date: 17 Jul, 2010 07:26:05

Message: 2 of 5

"Faisal Ahmed" <fap87@yahoo.com> wrote in message <i1r8qd$s1n$1@fred.mathworks.com>...
> I need help in plotting lines between points.
> Suppose, I start with creating 6 random points-
>
> x = rand(6,1);
> y = rand(6,1);
>
> So my points are (x(1),y(1)), (x(2),y(2)), (x(3),y(3)), (x(4),y(4)), (x(5),y(5)), (x(6),y(6))
>
> Now I want to draw straight lines between the points 1 & 5, 2 & 6, 3 & 4
> and plot them in a single diagram. So I get 3 straight lines.
>
> Any help would be highly appreciated.

Maybe that?
clear
clc
close all


 x = rand(6,1);
 y = rand(6,1);
 
 
 
 line([x(1) x(5)],[y(1) y(5)])
 hold on
 line([x(2) x(6)],[y(2) y(6)])
 hold on
 line([x(3) x(4)],[y(3) y(4)])
 

Subject: need help in plotting lines between points

From: Jan Simon

Date: 17 Jul, 2010 10:19:05

Message: 3 of 5

Dear Faisal,

> x = rand(6,1);
> y = rand(6,1);
> So my points are (x(1),y(1)), (x(2),y(2)), (x(3),y(3)), (x(4),y(4)), (x(5),y(5)), (x(6),y(6))
> Now I want to draw straight lines between the points 1 & 5, 2 & 6, 3 & 4
> and plot them in a single diagram. So I get 3 straight lines.

Try this:
  figure;
  line(rand(2, 3), rand(2, 3));

Good luck, Jan

Subject: need help in plotting lines between points

From: us

Date: 17 Jul, 2010 11:23:05

Message: 4 of 5

"zac "
> line([x(1) x(5)],[y(1) y(5)])
> hold on
> line([x(2) x(6)],[y(2) y(6)])
> hold on
> line([x(3) x(4)],[y(3) y(4)])

note: you do NOT need HOLD if you use LINE...

us

Subject: need help in plotting lines between points

From: Faisal Ahmed

Date: 18 Jul, 2010 14:51:04

Message: 5 of 5

thanx a lot everyone. my problem is solved!

-Faisal

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us