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

Click For Summary
SUMMARY

This discussion focuses on plotting multiple vectors starting from a specific point in MATLAB, specifically at the coordinates (2,2). The user initially attempts to use the plot function but finds it inadequate for multiple vectors. The recommended solution is to utilize the quiver function, which allows for the plotting of vectors by specifying starting points and vector components in matrix form. The user is advised to use meshgrid to create the necessary matrices for the x and y coordinates, as well as the vector components.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of vector representation in 2D space
  • Knowledge of the quiver function for vector plotting
  • Experience with matrix operations in MATLAB
NEXT STEPS
  • Learn how to use the quiver function in MATLAB for vector visualization
  • Explore the meshgrid function to create coordinate matrices
  • Investigate vector scaling and visual representation techniques in MATLAB
  • Review MATLAB documentation on plotting functions for advanced visualization options
USEFUL FOR

Mathematics students, engineers, and data scientists who need to visualize multiple vectors in MATLAB for analysis or presentation purposes.

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:

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 10 ·
Replies
10
Views
4K