Plot vectors 2D! With Matlab!

  • MATLAB
  • Thread starter abcdgb
  • Start date
  • #1
2
0

Main Question or Discussion Point

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 [Broken] 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:

Answers and Replies

  • #2
marcusl
Science Advisor
Gold Member
2,700
361
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 [Broken] 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:

Related Threads for: Plot vectors 2D! With Matlab!

Replies
6
Views
4K
Replies
0
Views
5K
Replies
3
Views
13K
Replies
2
Views
41K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
0
Views
1K
  • Last Post
Replies
3
Views
8K
Top