How to Plot Lines Between Coordinate Pairs

2 visualizaciones (últimos 30 días)
Ricky
Ricky el 26 de Feb. de 2014
Respondida: Prateekshya el 27 de Ag. de 2024
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...

Respuestas (1)

Prateekshya
Prateekshya el 27 de Ag. de 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.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by