Ming
Ming

Reputation: 497

How to plot an arrow in MATLAB

I am trying to plot a singular vector in MATLAB using arrow function, but MATLAB keeps giving me the error:

Undefined function 'arrow' for input arguments of type 'double'

How do I fix this?

Here is the MATLAB code:

function Plot_Singular_Vecor()
A=[1 1;2 3];

[U,S,V] = svd(A); % Find singular value decomposition.

figure;
theta = -pi:pi/50:pi;
circle = [cos(theta); sin(theta)]; 
plot(circle(1,:), circle(2,:), 'r'), grid
title('Right Singular Vectors, u1 and u2')
hold on;
arrow([0,0], [V(1,1), V(2,1)])

Upvotes: 1

Views: 12550

Answers (2)

lib
lib

Reputation: 2956

Alternatively you can use the built-in function quiver

quiver(0,0,V(1,1),V(2,1))

or the annotation function

annotation('arrow',[0,0],[V(1,1),V(2,1)])

Upvotes: 2

AGS
AGS

Reputation: 14498

You need to install the arrow function from MATLAB file exchange, or if you have the function, make sure it's in your PATH.

Upvotes: 3

Related Questions