MATLAB How Can I Plot Multiple Vectors Starting at the Same Point in Matlab?

AI Thread Summary
To plot multiple vectors starting at the same point in MATLAB, the quiver function is recommended. The x and y starting points can be defined using meshgrid, while the vector components are specified in matrices for u and v. For example, to plot vectors A and B starting at (2,2), set x and y to meshgrid([2,2]) and u and v to meshgrid([5,0]) and meshgrid([0,2]). To include additional vectors, simply expand the u and v matrices accordingly. It's also advised to avoid reassigning built-in MATLAB variable names like "pi" to prevent conflicts.
abcdgb
Messages
2
Reaction score
0
Hi... I have four vectors that I need together in one plot and also they should start at (2,2)

Vector A is a=[5 0]
B is b=[0 2]
I obtained unit vector and I need something similar to http://www.scribd.com/doc/13353344/Fundamentals-of-Electromagnetics at page nine


I know the following commands

pi=[2,2];
plot( [pi(1),pi(1)+v(1)] , [pi(2),pi(2)+v(2)])

It works but not with four vectors. What should I do?


I'm not pretending you to do my homework so that I'm asking for the plot
 
Last edited by a moderator:
Physics news on Phys.org
abcdgb said:
Hi... I have four vectors that I need together in one plot and also they should start at (2,2)

Vector A is a=[5 0]
B is b=[0 2]
I obtained unit vector and I need something similar to http://www.scribd.com/doc/13353344/Fundamentals-of-Electromagnetics at page nine


I know the following commands

pi=[2,2];
plot( [pi(1),pi(1)+v(1)] , [pi(2),pi(2)+v(2)])

It works but not with four vectors. What should I do?


I'm not pretending you to do my homework so that I'm asking for the plot
First a comment on Matlab style: It's generally a poor idea to reassign built-in Matlab function or variable names such as you did in the first line. In Matlab, pi is preassigned the value 3.14159...

On to your question: use the command quiver to plot vectors. The arguments are passed in the form of matrices specifying the x and y starting points and the u and v vector components. For your two vectors a and b:

x = meshgrid([2,2]);
y = meshgrid([2,2]);
u = meshgrid([5,0]);
v = meshgrid([0,2]);
quiver(x,y,u,v)

Add columns to plot more vectors, e.g., u = meshgrid([5,0,14,22,...])
Matlab renders the arrow a little shorter than you expect, for visual clarity, but you can rescale if desired. REad the help page for quiver.
 
Last edited by a moderator:
Back
Top