How to Plot Lines Between Coordinate Pairs
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Prateekshya
2024-8-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!