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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With