How to Plot Lines Between Coordinate Pairs
2 views (last 30 days)
Show older comments
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...
0 Comments
Answers (1)
Prateekshya
on 27 Aug 2024
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.
0 Comments
See Also
Categories
Find more on Startup and Shutdown 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!