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

In summary, to plot four vectors starting at (2,2) in Matlab, use the quiver command with x and y matrices of the starting points and u and v matrices of the vector components. Use meshgrid to duplicate values as needed. Remember to avoid reassigning built-in function or variable names.
  • #1
abcdgb
2
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
  • #2
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:

1. What is a plot vector in 2D with Matlab?

A plot vector in 2D with Matlab is a graphical representation of a set of data points in two-dimensional space. It is created using the "plot" function in Matlab, which allows for the visualization of data in a clear and concise manner.

2. How do I plot 2D vectors in Matlab?

To plot 2D vectors in Matlab, you can use the "plot" function with the x and y coordinates of the data points. Alternatively, you can use the "quiver" function to plot vectors as arrows, showing both direction and magnitude.

3. Can I customize the appearance of my 2D plot vectors in Matlab?

Yes, you can customize the appearance of your 2D plot vectors in Matlab by using various formatting options such as color, line style, and marker style. You can also add titles, labels, and legends to your plot to make it more informative.

4. How can I add multiple 2D plot vectors on the same graph in Matlab?

To add multiple 2D plot vectors on the same graph in Matlab, you can use the "hold on" function to prevent the previous plot from being erased. Then, use the "plot" or "quiver" function to add the additional vectors to the same graph.

5. Is there a way to save my 2D plot vectors in Matlab for future use?

Yes, you can save your 2D plot vectors in Matlab by using the "saveas" function. This allows you to save your plot as an image file, such as PNG or JPEG, which can be used for future reference or for inclusion in reports or presentations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
569
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
937
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
996
Back
Top