How to Plot Lines Between Coordinate Pairs

1 view (last 30 days)
Ricky
Ricky on 26 Feb 2014
I've spent quite a while searching the forums, re-reading answers, testing peoples replies and supposed solutions.... but can't get to the answer to this and it's driving me mad. A much simplified version of the problem is:
Consider two arrays: a=[1,1;1,2;1,3;1,4]
b=[2,1;2,2;2,3;2,4]
The pairs of co-ordinates are on each row, i.e. (1,1) is paired with (2,1), (1,2) with (2,2) etc. How do we join these pairs create 4 horizontal lines, without using loops.
We do NOT want a line from, e.g. (2,1) to (1,2) as this pair does not exist.
The following loop does the job: for i=1:4
plot([a(i,1),b(i,1)],[a(i,2),b(i,2)])
hold on
end
Replacing the 'i' with a ':' doesn't work, it draws two vertical lines! I'm thinking there should be a one line, vectorised answer, but I can't figure it out. Thanks in advance...

Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!