Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw vectors (physical 2D/3D vectors) in MATLAB?

Tags:

I want to know the simplest way to plot vectors in MATLAB. For example:

a = [2 3 5];
b = [1 1 0];
c = a + b;

I want to visualize this vector addition as head-to-tail/parallelogram method. How do I plot these vectors with an arrow-head?

like image 339
Aamir Avatar asked Dec 26 '09 00:12

Aamir


People also ask

Can I plot vectors in Matlab?

M — Matrix to plotMatrix of column vectors to plot, specified as a R -by- Q matrix of Q column vectors with R elements. R must be 2 or greater. If R is greater than 2, this function only uses the first two rows of M for the plot.

How do you write vectors in Matlab?

You can create a vector both by enclosing the elements in square brackets like v=[1 2 3 4 5] or using commas, like v=[1,2,3,4,5]. They mean the very same: a vector (matrix) of 1 row and 5 columns. It is up to you.


1 Answers

a = [2 3 5];
b = [1 1 0];
c = a+b;

starts = zeros(3,3);
ends = [a;b;c];

quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3))
axis equal
like image 106
Amro Avatar answered Sep 19 '22 12:09

Amro