How to Plot Lines Between Coordinate Pairs

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...

답변 (1개)

Prateekshya
Prateekshya 2024년 8월 27일

0 개 추천

Hello Ricky,
Replacing "i" with a colon works in the latest version of MATLAB. I assume you are using an older version. Please update MATLAB on your system so that you can use the latest featues and functionalities.
Thank you.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

질문:

2014년 2월 26일

답변:

2024년 8월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by