# MATLAB Language Drawing Arrows

## Example

Firstly, one can use `quiver`, where one doesn't have to deal with unhandy normalized figure units by use of `annotation`

``````drawArrow = @(x,y) quiver( x(1),y(1),x(2)-x(1),y(2)-y(1),0 )

x1 = [10 30];
y1 = [10 30];

drawArrow(x1,y1); hold on

x2 = [25 15];
y2 = [15 25];

drawArrow(x2,y2)
`````` Important is the 5th argument of `quiver`: 0 which disables an otherwise default scaling, as this function is usually used to plot vector fields. (or use the property value pair `'AutoScale','off'`)

``````drawArrow = @(x,y,varargin) quiver( x(1),y(1),x(2)-x(1),y(2)-y(1),0, varargin{:} )
drawArrow(x1,y1); hold on
drawArrow(x2,y2,'linewidth',3,'color','r')
`````` If different arrowheads are desired, one needs to use annotations (this answer is may helpful How do I change the arrow head style in quiver plot?).

The arrow head size can be adjust with the `'MaxHeadSize'` property. It's not consistent unfortunately. The axes limits need to be set afterwards.

``````x1 = [10 30];
y1 = [10 30];

x2 = [25 15];
y2 = [15 25];

xlim([1, 100])
ylim([1, 100])
`````` ``````function [ h ] = drawArrow( x,y,xlimits,ylimits,props )

xlim(xlimits)
ylim(ylimits)

h = annotation('arrow');
set(h,'parent', gca, ...
'position', [x(1),y(1),x(2)-x(1),y(2)-y(1)], ...
props{:} );

end
``````

which you can call from your script as follows:

``````drawArrow(x1,y1,[1, 100],[1, 100],{'Color','b','LineWidth',3}); hold on
drawArrow(x2,y2,[1, 100],[1, 100],{'Color','r','LineWidth',3}); hold on
``````  PDF - Download MATLAB Language for free