File Exchange

image thumbnail


version (58.2 KB) by Erik Johnson
Draw a line with an arrowhead.


Updated 25 May 2016

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week Popular File 2012 2013

ARROW (5/25/2016) Draw a line with an arrowhead.

ARROW(Start,Stop) draws a line with an arrow from Start to Stop (points should be vectors of length 2 or 3, or matrices with 2 or 3 columns), and returns the graphics handle of the arrow(s). By itself, ARROW will use the mouse to allow selection.

ARROW DEMO & ARROW DEMO2 show 3-D & 2-D demos of the capabilities of ARROW.

ARROW PROPERTIES shows the properties that can be set (length, base angle, tip angle, width, which ends have arrowheads, etc.)

Cite As

Erik Johnson (2021). arrow (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (238)

Erik Johnson

@Sara: ignore my suggestion from earlier. You are using an old version of arrow (probably pre 2005?). Download the current version here.

Erik Johnson

try changing "ax = o * gca" to "ax = repmat(gca,size(o))"

Sara Mustafi

I used the arrow around December 2020 the last time and it worked perfectly. Now I went back to running the same script and I get the error:

Undefined function 'mtimes' for input arguments of type ''.

Error in arrow (line 406)
ax = o * gca;

Error in Sec_fig_phi_fixed_magnon (line 216)

I have MATLAB R2019b. I tried deleting and redownloading this version of arrow, still the same mistake...

I also tried Michael Xie's modifying the code, still doesnt work.

Flint O'Neil

Fixes the bugs in matlab's inbuilt annotate('arrow') function


Instead of calling axis(axis) prior to the function call, is there any way to update the function to pass an axes handle as the first argument, similar to other plot functions?



zixuan liang

Erik Johnson

@George, yes. Something like this:
>> plot([0 1],[0 1]); axis(axis);
>> x=(0.1:.2:.9)'; h=arrow([x .1+x*0],[x .9+x*0]);
>> set(h,{'FaceColor' 'EdgeColor'},repmat({'r';'g';'b';'m';'k'},1,2))

George Marrash

If i use arrow to plot 4 vectors is it possible to have each vector be a different color?

Michael Xie

Very helpful routine!
In 2018b and later (and possibly some earlier versions), the syntax
>> h = arrow(start, stop);
does NOT return a patch object handle 'h' for the arrow. Instead it's just a double.
This is due to how the array of handles is initialized. This can be fixed by a change on line 949:
if isempty(oldh), H=zeros(narrows,1); else, H=oldh; end;
if isempty(oldh), H=gobjects(narrows,1); else, H=oldh; end;

Hope this helps others who are struggling to get the handle to the arrows.

Thank you for your contribution!

Xingwang Yong

Perfect, thank you!

Jalil Kianfar

E Galois

Mao Shuman


Cristian Porter

Haoyu Liu

Chris Endemann

Does this include functionality to depict the arrow at the center of a line (or anywhere really aside from just the tail/head of the line)?

Erik Johnson

Mesbahose, do "help arrow" to see how it is used. If you are trying to make the arrow red, arrow(r,u,'Color','r') is the correct syntax.

Mesbahose Salekeen

What's the problem. I get an error!!!!

Error using arrow (line 190)
ARROW requires that the property 'r' be paired with a property value.
Error in Cycloid (line 12)

The code:
% Graph the cycloid curve
rad = 1; omega = 1;
t = linspace(0, 4*pi, 121);
x = rad*(omega*t -sin(omega*t));
y = rad*(1 - cos(omega*t));
hold on
% Add the velocity vectors
for s = linspace(0, 4*pi, 25)
hold off

Rostislav Teryaev

1. If you need legend.
Add to the top of the function this.
function arrow2(varargin)
global test
test = varargin{3};
varargin(3) = [];

(And "global test" to the top of the arrow function)
function [h,yy,zz] = arrow(varargin)
global test
Now you can call arrow2([1, 2], [3, 4], 'YouLegend', ...)
2. If you need to hide mentioning arrows from legend
in line 969 or 971 instead of
H(k) = patch(xyz{:});
write this
H(k) = patch(xyz{:},'HandleVisibility', 'off');


Jocelino, you probably want to set you xlimits and ylimits before calling arrow, e.g.

hold on, grid on, box on
xlim([2000 3000]),ylim([1e5 2e6])
arrow([2390, 0.46*1.2e6],[2335, 2.5e5], 'Length', 10)
xlabel('x label')

Erik Johnson

m: it looks fine for me. Please email me (see email address in the m-file) a screenshot, and let me know what version of MATLAB you are using and on what platform.

Erik Johnson

Jocelino Rodrigues: I cannot reproduce your error. What version of MATLAB are you using and on what platform?


When I use this with a LineStyle such as dashed, the dashes look odd, with variable spacing between the dashes, e.g.

>>figure,xlim([0 2]),ylim([0 1]),arrow([1,0],[1,1],'LineStyle','--')

Anyone know why?

Jocelino Rodrigues

Arrow looks good but when it's plotted, my subplot(2,1,2) xlabel goes off the figure. I've tried all the solutions suggested in the comments below, but none of them have worked for me.
When I call arrow fixlimits I get a message: "ARROW does not remember any axis limits to reset."

Can anyone help? My code is below.




hold on; grid on; box on;

hold on; grid on; box on;
arrow([2390, 0.46*1.2e6],[2335, 2.5e5], 'Length', 10);
arrow fixlimits;

Jeff Harris

Matthew Loew

Erik Johnson

Antonietta: not sure what you mean. Can you elaborate? What version of MATLAB on what platform? Can you give some code to demonstrate your problem.

Yanqing Pan

Antonietta Chaliou

Great function. Although I've encountered a different problem, the script seems to be working perfectly without any errors but the output figures keep disappearing. If anyone can help it would be immensely appreciated and have my eternal thanks.


Takes some getting used to, but the comments are a huge help and once I got the hang of it, this was really useful. Thanks!

Marat Zhe

Marat Zhe

Marat Zhe

Marat Zhe

Erik Johnson

FYI, Shuliang's error went away when he reinstalled.

Christophe Geuens

Ruizhao Zhu

Erik Johnson

Shuliang, It's not clear how that error could occur: there is no '*' operator on line 406 that is giving the error. Can you let me know what version of arrow you are using (look for the date on the Copyright line in the arrow.m code)? Please click on my name, click "view profile" and click on "Contact" to e-mail me.

Shuliang Tian

Sorry, I also meet some problem(revision R2018b)
I tried Tomy's code for a trial and it shows:
Undefined operator '*' for input arguments of type ''.
Error in arrow (line 406)
if ~isempty(crossdir),

Nicklas Nyboe

xinglong fang

Tomy Duby

Eric, Thanks! Yes, I was using an old version of arrow.m function (5/20/09). Downloading the latest version resolved the issue. So works fine on R2018a and even R2018b.

Erik Johnson

Tomy's error seems to be with a (very) old version of arrow (circa 2009) and should not occur with the current version. Let me know if otherwise.

Tomy Duby

Sorry, but does not work for me (revision R2108a):
x = 0:pi/100:2*pi;
y = sin(x);
hold on
arrow( [0, 0], [1, 0] )
Undefined operator '*' for input arguments of type ''.
Error in arrow (line 423)
ax = o * gca;

Luigi Famiglietti

Diana Shakirova

Perfect on 2014b


Dage Shang

great function. works perfectly.

Riccardo Perni

Zaiyang ZHOU

Thanks a lot. This script perfectly helps me with the problem of adjusting headsize of arrows when using quiver function.

Chuan He

% You may want to execute AXIS(AXIS) before calling ARROW so it doesn't change
% the axes on you; ARROW determines the sizes of arrow components BEFORE the
% arrow is plotted, so if ARROW changes axis limits, arrows may be malformed.

Ondrej Panek

mcdull hall

Great work.
If someone needs to hide the arrow, it can be achieved by setting the XData and YData of the arrow handle (a patch obj) to empty arraies; to redraw the arrow, just use the function as arrow(h_arrow, 'Start',[x1 y1],'Stop',[x2 y2]), as mentioned in the m-file.
Thanks again.

Hans-Martin Schwab


It works well if you have some kind of nice axis limits. But otherwise you have to play with arrow appearance a lot..
Example: arrow([0 1e6],[1000 1e6]); - it doesnt produce an arrow one would expect..

Jack Lee

William Nesse

The arrow drawing works great, but before I called the function, I plotted two other curves and called the legend function to give them labels (just two labels). However, after calling legend I then call four arrows and they show up in the legend and I can't seem to exclude them. In the legend, the four arrows show up with the labels "data1", "data2", "data3", "data4". I can find no way to exclude them.

I'm using 2017a

Patrick Hammer

I'm seeing some strange behavior when the renderer is painters where part of the tip angles up a little bit.

Shujaat Khan

Cheng Zeng

Teije van der Horst

Morten Larsen

Frantisek Brazdik

Brendan Blanchard

Very useful! I've had quite a bit of trouble with quiver() in the past since it's not meant to draw a shape so much as vectors, but this does the trick!

Note on axis limits: The warning "Warning: ARROW changed the axis limits when adding the arrow.
Call ARROW FIXLIMITS to reset them now." does not have a warning.identifier to allow it to be suppressed, but calling "axis(axis)" before using arrow() prevents the error from occurring.


I'm using this soooo much, however, it would be nice if you could add the ability for the arrows to always 'face' the camera, so that they're not flat in 3d space when rotating.

Stephen Elias

Yujiao Sun

Zachary Bassett

Roberto Agromayor

Farhad Mohammadi

Shima Nazari

Mohammad Akmal

Collin Smith

Excellent documentation, and very useful packaged function!

tao lu

Erik Johnson

Friedhelm, It only happens in debugging? Can you email me some code? (Email address is in the m-file; or click on my name then "view profile" then "Contact".)

Friedhelm Krumm

Dear Erik, I am running several Matlab versions (2016a, 2016b and 2017a) and the "strange behavior" is that the arrows are distorted in both, length and shape of the arrow head. Meanwhile I noticed that calling "arrow" in pointwise fashion (in a for-loop) and debugging the code step by step is causing the problem. If I avoid debugging then the problem disappears. Many thanks. Friedhelm

Erik Johnson

Can you describe the strange behavior? What MATLAB version? Can you provide a minimal working example to demonstrate it?

Friedhelm Krumm

First of all, this is a great function, which I am using now for many years. Thanks! However, today I observed a strange behaviour after calling it twice (different figures) but with identical arguments and I wonder what the reason may be. The handle argument lists are identical. Any help would be highly appreciated. Thanks. Friedhelm Krumm

Alex Kotov



looks perfect

mohammad karami


Yiming Pan

Awesome work!



Fantastically good.

Yuki Hayashi


Baoning Wu

With perfect control of properties, this is exactly what I want!

Jing Lou

Nice work!


Nice Job! Works well with my oldest version of MATLAB.

Here is my line of the code:

Both tStart an tStop are numerical parameters and pre-defined.


quan yuan

Erik Johnson

Daisuke, I've not seen this problem before. What version of MATLAB? Can you give a minimal working example to demonstrate it?


When I drew a vertical arrow, the line got off from the arrow head (see the url for a picture). Is there a way to fix this? If not, could you tell me how I could adjust this ?

Erik Johnson

After a long hiatus, arrow has been updated for HG2 compatibility. I _think_ most of the comments below have been incorporated.


What's going on with this error:

views = get(ax(:),{'View'});

Error in arrow (line 961)
mask = arrow_is2DXY(oldaxlims(:,1));

Thanks anyone!

Matthew Gruber

Works well on (R2015b) after putting in the exact changes that Johannes recommends (2 posts down). Before that it didn't work on my version but did on other matlab installs I have at school etc., getting the same error people are talking about.


Ooops, my bad. You must implement all of the suggestions by Justin and Brenton.


For everybody that has problems running the current arrow.m version on newer Matlab versions, please follow the corrections suggested by Justin and Brenton from 11 Nov 2014. I adapted them on Matalb R2015a and it works....

Here the suggested changes copied from their posts:

Previous: Line 423 ax = o * gca;
Update: ax = repmat(gca,narrows,1);

Previous: Line 590 curT = get(curax,'Xform');
Update: [azA,elA] = view(curax);
curT = viewmtx(azA,elA);

Brenton: Piggy-backing on Justin's edits, update with the following:

LINE 504: oldaxlims(min(find(oldaxlims(:,1)==0)),:) = [ii reshape(axl',1,6)];

LINE 960:
lims = get(ax(oldaxlims(:,1)),{'XLim','YLim','ZLim'})';

LINE 962:
mask = arrow_is2DXY(ax(oldaxlims(:,1)));

Amir Paster

It doesn't work in Matlab 2015a

>> arrow
Undefined operator '*' for input arguments of type ''.

Error in arrow (line 423)
ax = o * gca;

ankit dixit


Thanks Justin and Brenton! I got it to work for MatLAB version 2015b following your edits.

Leonard Wayne

As an alternative, there is now the DaVinci Draw toolbox,, which uses low-level Matlab commands like plot() and patch() to draw mid-level shapes like arrows. Example syntax:

davinci( 'arrow', 'X', [0 10], ...
'Y', [0 2], ...
'Shaft.Type', 'rectangle', ...
'Shaft.Width', 1, ...
'Head.Length', 2.5, ...
'Color', 'w', ...
'EdgeColor', 'k', ...
'LineWidth', 2.5 )


Same here in 2015b, not working properly
>> arrow DEMO
Undefined operator '*' for input arguments of type ''.

Error in arrow (line 423)
ax = o * gca;

Error in arrow>arrow_demo3 (line 1273)
h1 = feval(mfilename,[axlim(1) axlim(4) 4],[-.8 1.2 4], ...

Error in arrow (line 142)


Zhigang Xu

Dear Author,

It seems that the ARROW cannot work with Matlab R2015a version. I got an error message as

Error in arrow (line 406)
ax = o * gca;

Can you fix it? Thanks!


Andrew Boysen

Thank you Daniel Claes - that worked for me!

Daniel Claes

It is not mine, but I found a working version it on GitHub (works for 2015a):

Good contribution. Thanks!

Jakob Sievers

Thank you for the preceeding comments. They helped making this otherwise excellent function work. 5 stars for the function. 0 stars for the slow updating. I strongly encourage the author update this function according to the comments made.

Min-Chi Shih

Thanks to Justin A., Brenton, and Bruce Elliott, I have got it to work as well (R2014b). This is much better than the built-in annotation.m.

Rachael Hardman

Thank you for the comments - I've got it to work now too.


Thanks to the comments of Justin A., Brenton and Bruce Elliott, I got this fantastic file working for the arrows I needed in MATLAB R2014b. Author: please update this file to make it compatible with the new graphics system.



did anyone manage to make
arrow DEMO
work with 2014b? would it be possible to upload an updated working version?

Bruce Elliott

Thanks to Justin and Brenton for the recommended mods for R2014b. I have another set of related changes.

These changes will suppress warnings about use of the graphics object property "EraseMode", which is no longer used. I believe the only purpose of these lines was to temporarily change the EraseMode and then to reset it to its original value.

REMOVE LINES 1031, 1032, 1033, 1065:

oldArrowProps = {'EraseMode'};
oldArrowValue = get(H,oldArrowProps);
set(H,'EraseMode','background'); %because 'xor' makes shaft invisible unless Width>1



Piggy-backing on Justin's edits, update with the following:

LINE 504: oldaxlims(min(find(oldaxlims(:,1)==0)),:) = [ii reshape(axl',1,6)];

LINE 960:
lims = get(ax(oldaxlims(:,1)),{'XLim','YLim','ZLim'})';

LINE 962:
mask = arrow_is2DXY(ax(oldaxlims(:,1)));

Justin A.

Strike that. It works for one arrow, but not the demo.

Justin A.

I was able to get it to work in 2014b with 2 changes:

Previous: Line 423 ax = o * gca;
Update: ax = repmat(gca,narrows,1);

Previous: Line 590 curT = get(curax,'Xform');
Update: [azA,elA] = view(curax);
curT = viewmtx(azA,elA);

Yang Liu

@David, @Tobias, I have encountered the same issue.
Did you manage to resolve the problem? Thanks in advance!


Love this script, but it looks like there's a fundamental incompatibility with the new 2014b graphics system, in which gca no longer returns a number. Simply running the demo (arrow DEMO) returns the error:

Undefined function 'mtimes' for input arguments of type
Error in arrow (line 423)
ax = o * gca;

Liviu Ivanescu

Nice function, but unfortunately it doesn't accept axes handle, like plot. In same cases, like Maltab GUI, one cannot just set the axes before making the plot.


I was a bit sceptical, but this is actually a very useful and well-documented function. Many thanks


You are brilliant. Thank you very much for your hard work and masterful technique.


Works nicely, but i did find a bug:
an exactly vertical arrow (from [0 0 0] to [0 0 1]) is plotted with a length of ~16 reaching far in the negative z-domain. Just type in
arrow([0 0 0],[0 0 1])
and see.

Does someone know a solution to this?

with kind regards,

Peter Caday

@Li, after reading Rajib's comment below, I saw you can change color in one function call:

h = arrow(..., 'EdgeColor', 'g', 'FaceColor', 'g');

@Tobias, I don't have 2014b, but you could try replacing line 423 with:

ax = repmat(o, narrows, 1);

Tobias Benjamin Gram

After updating Matlab to 2014b, arrow.m is not working. It is stopping in line 423 with the error:

Undefined function 'mtimes' for input arguments of type ''.

Error in arrow (line 423)
ax = o * gca;

Can somebody please help me?


Terrific. Thanks.
For those of you who would like to have a small gap between the arrow and the start and end point (e.g. so as not to obscure a marker), I've written a slight update (note: not compatible with arrow.m properties directly, but you could easily adapt):

function [varargout] = my_arrow(start,stop)
arrow_gap_pc = 0.05; % defines gap size relative to size of initial arrow
[th,phi,r] = cart2sph(dx,dy,dz);
arrow_gap = arrow_gap_pc*r;
[x1,y1,z1] = sph2cart(th,phi,arrow_gap);
b = start+[x1 y1 z1];
e = stop-[x1 y1 z1];
ah = arrow(b,e);
if nargout == 1
varargout{1} = ah; end

Pegah Hosseini

I think this is one of the best functions I have ever stumbled upon. Thanks alot.


Li Zhang

Useful! How to change the color of the arrow ?


ammar al jodah

Harish Babu Kankanala

Alexandros Iliopoulos

Jo Williams

Very useful, thanks. The help suggests using AXIS(AXIS) to fix the limits, I think the same effect can be acheived with AXIS MANUAL, which would be clearer.
It's also not obvious that the arrow will be a patch object, so has properties like edgecolor, facecolor, rather than line properties.

Jan Motl

Jan Valdman


Sisi Ma

Rajib Mozumder

I wrote the following code:

hold on;
Z1 = 500;
arrow([max(X) max(Y) Z1],[min(X) min(Y) Z1],15,'BaseAngle',60, 'FaceColor',[0 1 0])

I want to make outputs (which must contain the line along with arrow head) in X-Z plane; i.e. view([180 0]), not in 3D which is good for visualization only. Unfortunately, though the line is visible, the arrow head is not seen when I go into 2D view. I tried to include 'CrossDir',[0 0 1] as suggested by the author of the script, but it didn't help. Any suggestion?

Michael Chan

How do you turn off the arrow heads at either ends of the start and stop points?

Matthew M.

Very helpful and thorough! I only have a couple of minor quibbles - 1) the author didn't make it totally clear what normal MATLAB line properties you should use to change the arrow color and arrowhead color. But it's not too hard to figure out. 2) The author didn't assign message identifiers to the warnings (like for changing the axis limits). I edited the function to add message identifiers so I could turn them off - don't need my Command Window cluttered up with a lot of orange text.

Haochen Tang


Does anyone know how to add an arrow to the legend? I'm using arrow.m to draw arrows which represent data on the plot and it would be helpful to have a blue arrow in the legend.

Kent Leung

@Matthias, I had this problem too and just stumbled on a solution. (In fact, the problem for me was that the xlabel was disappearing.) To fix this I did:

ax1=subplot(2,1,1); [...]
axes(ax1); arrow([x1 y1],[x2 y2]); arrow fixlimits;

I always do "fixlimits" just in case. The reason I tried this was because in the help file:
"You may want to execute AXIS(AXIS) before calling arrow so it doesn't change the axes on you; arrow determines the sizes of arrow components BEFORE the arrow is plotted, so if arrow changes axis limits, arrows may be malformed."

It's not obvious that this fixed the subplot resizing problem, but it worked!


By far the easiest way to draw arrow compared with arrow3.m and mArrow3.m.

Jiangmin zhang

Matthias Hunstig

Generally works fine. However, I use subplots, e. g. 3 x 2, and some of them have arrows. Now the arrows change the size of the subplot so that the subplots are no longer of equal size. Any idea how to correct that?


How do I make the arrows dashed, and make the color for each arrow different, corresponding to its z value?

Adding the 'Linestyle',':' for dashed line option makes the arrows look rather strange.

For the colors, I tried creating an nx3 matrix lineColors where each row is a color for the corresponding element, and added the option " 'EdgeColor',lineColors ", but got an error:

"Color value must be a 3 element numeric vector"

Any help is appreciated. Thanks.

Yuanye Wang

exactly what I need. thanks a lot.


Regarding W & Jacopo,

setting the view before the arrow functions solves your problem e.g.:

clc; clear; close all

xvector=[1 0 0];
yvector=[0 1 0];
zvector=[0 0 1];

grid on
daspect([1 1 1])
xlabel('x [mm]', 'FontWeight', 'bold')
ylabel('y [mm]', 'FontWeight', 'bold')
zlabel('z [mm]', 'FontWeight', 'bold')

%Here goes the view setting
view([1 1 1])

arrow([0 0 0],xvector, 'EdgeColor','k','FaceColor','k')
arrow([0 0 0],yvector, 'EdgeColor','b','FaceColor','b')
arrow([0 0 0],zvector, 'EdgeColor','r','FaceColor','r')

%Not here
%view([1 1 1])

Don't no why but seems to work!


John Colby

Wonderful. Thank you, Erik!!!



> Christopher This code, at least on >R2009a, looks very strange.
>close all; clc;
>axis([-1 1 -1 1 -1 1])
>I'm really having trouble with 3-D plots >and arrows pointing along the 3rd axis.

I got the same problem on Matlab R2010a (7.10.0)


Using arrow with this script yields an unusually long arrow in the z direction, which is quite annoying. I wish the z arrow didn't become long.

clc; clear; close all

xvector=[1 0 0];
yvector=[0 1 0];
zvector=[0 0 1];

grid on
daspect([1 1 1])
xlabel('x [mm]', 'FontWeight', 'bold')
ylabel('y [mm]', 'FontWeight', 'bold')
zlabel('z [mm]', 'FontWeight', 'bold')
arrow([0 0 0],xvector, 'EdgeColor','k','FaceColor','k')
arrow([0 0 0],yvector, 'EdgeColor','b','FaceColor','b')
arrow([0 0 0],zvector, 'EdgeColor','r','FaceColor','r')
view([1 1 1])

Help would be greatly appreciated.

William Mische

This is great, I messed around with the annotations for 1.5 hours before finding this. Once I found it everything was working the way I wanted it to in a couple of minutes. Great Work!

Dmytro Lituiev

Marco idiart

Perfect. Just what I was needing.


Very nice utility function. I just wonder if it is possible to fix the arrow head size so that it does not change with axis- zoom or resize. Thanks!

Richard Crozier

Really useful, thanks!

Miguel Gil-Pugliese

Thanks :)


Very nice, thanks


can this function specify the 'LineStyle', such as '-' , '--' , '-.' , and ':'?
how to do?
thank you.

Rishabh Kasliwal

thanks a lot. I was trying to make a arrow in a gui window. was having difficulty in correctly saving the arrow location. using your code it works perfectly :)


Overall, the script is very useful. However, when using this arrow script, the legend is messed up. Some of the legend symbols would show as "black" squares instead of the correct symbol. When the arrow script is not used, the legend is displayed correctly.

hajime yamada

Could anybody please let me know the following:

1. How to change the size of the arrow?
2. Please let me know how to change the type of the arrow head.
3. If possible, please let me know how to have arrow at both the head and tail of the vector.
4. Instead of arrow, please let me know how I can have a dot at both ends of the vector?
5. How to change the line type?


ben harper

can you please include the color options that you write on these comments to the code help lines
thank you

Jiangmin zhang



Works great, but the Arrowtips do not look perfect by default as they are the connection of two line ends and therefore not round in pdf printouts.
You can workaround this issue by drawing the arrow in the opposite direction and use parameter: 'End','start'.
But nonetheless it would be nice if they would be perfect by default ;-)




This code, at least on R2009a, looks very strange.
close all; clc;
axis([-1 1 -1 1 -1 1])

I'm really having trouble with 3-D plots and arrows pointing along the 3rd axis.

Ryan Molecke

I found this implementation to be slow and lacking. Admittedly I was drawing thousands of arrows at extremely short lengths. Here is an inline function I wrote in about 5 minutes to draw simple arrows.

function out = draw_arrow(startpoint,endpoint,headsize)
%by Ryan Molecke

v1 = headsize*(startpoint-endpoint)/2.5;

theta = 22.5*pi/180;
theta1 = -1*22.5*pi/180;
rotMatrix = [cos(theta) -sin(theta) ; sin(theta) cos(theta)];
rotMatrix1 = [cos(theta1) -sin(theta1) ; sin(theta1) cos(theta1)];

v2 = v1*rotMatrix;
v3 = v1*rotMatrix1;
x1 = endpoint;
x2 = x1 + v2;
x3 = x1 + v3;
hold on;
% below line fills the arrowhead (black)
fill([x1(1) x2(1) x3(1)],[x1(2) x2(2) x3(2)],[0 0 0]);
% below line draws line (black)
plot([startpoint(1) endpoint(1)],[startpoint(2) endpoint(2)],'linewidth',2,'color',[0 0 0]);

Rob Campbell

Useful in many ways but the code is very complicated and it's not clear how to attain specific effects without trawling through the function body. Why not put demo code in a separate file?



Lorenzo Guerrasio

It looks really great...I'll start use instead of quiver!

never change

amazing,very useful

The arrowheads look distorted. Even the arrowheads in the demo look distorted.


Excellent. One little problem is that the arrow created is a little different from the one inserted manually through the "insert" menu. For example, the position can not be adjust by mouse.


to set the color of the arrow, see this example:
axis([0 3 0 3 0 3]);
grid on
h=arrow([3 3 3],[0 0 0],36,'BaseAngle',60);
set(h, 'FaceColor', 'b');
set(h, 'EdgeColor', 'r');
Awesome application!


very useful.

Saeed Taherion

Leonardo Duarte

lili kalmer

Joselito Dimayuga

the purpose of this Dir or format is for ?????

Dmitry Vasilyev

OMG! Just exactly what I was looking for! Excellent job, thank you Eric!

GDR! x

One can change the colour of an arrow by specifying 'FaceColor' and 'EdgeColor' properties, which is, unfortunately, not documented.

Xuzhang Shen


Alex Fard

Matthijs Klomp

Works great.

Tuan Hoang

sorry, how to add this graphic handle (return value) to an existing axes, figure.

Ahmet Sacan

Does not work when called in a deployed application (i.e., when called from the executable generated using mcc).

Rutty Bee

Ruins the figure when plotting 3-D arrows with z-components. In this case, the width of the arrowhead becomes so large that the plot is rendered unusable. This is the case no matter how one tries to set its size.

Dustin Kruse

works perfectly

Jorge Marin

B Gurt

Does exactly what it needs to do.

jonny e

Excellent and easy to use. I'd emphasize that one should call axis(axis) prior to plotting the arrow, or the axis limits will get reset which will render the arrow incorrectly. This is noted in the help, but tucked towards the bottom.

Ramesh Rajasekaran

Vassili Pastushenko

does not point to (1,1)

Vassili Pastushenko

Good job. A small remark:

arrow([0 0],[1 1],50,10,30)

does not point to (0,1).

Probably it would be reasonable to add a feature of automatical swapping baseAngle and tipAngle, if baseAngle < tipAngle.

Arun Karthi Subramaniyan

Great tool. Very easy to use with detailed documentation. Thanks for sharing it with us.

J Xu

this program is really good, easy-use. 3x Erik.

Nithya C.R.

The program is really great with all the aspects of plotting a directed line excellently covered.

heath kitson

thanks eric


This is great. I hate how MATLAB uses normalized figure coordinates in their annotation() call for drawing arrows. It makes no sense and someone at MathWorks got lazy, so it becomes nearly useless. This code is exactly what they should have done.. good job Erik!

Jasper Menger

Nicely done. A shame by the way Matlab doesn't seem to have a builtin function for drawing arrows from the command line.

Very satisfied

Exactly what I needed. Perfect!

super tanne

Shane Lin

I add the following comment at the file head. arrow(Start,Stop,'EdgeColor','b','FaceColor','b') color arrow.

Vijaykumar Sathyamurthi

Thanks for this excellent tool. I hope you continue writing such winderful codes!!!

Sharoni Shafir

Works great, thanks!

Amit Kesar

Very good. Thank you.

Changshun Deng

Good script!

Dave Cogdell

This code (specifincally including the documentation (which is at the same time incomplete and inadequate) is far too complex for the simple thing(s) it does. I believe the author is an engineer: he should refrain from trying to write like a computer scientist and write like an engineer.

Janik Zikovsky

Very good, better than annotation('arrow') because it is in axis units!

Ian Mackenzie

Evan Westwood

Couldn't figure out how to make the arrow line and arrow head have a specific color. Arrowheads didn't look as nice as those you might plot in drawing/presentation packages such as Powerpoint.

Rattikan Saelim

Nathaniel de Lautour

Superb effort. Highly configurable, easy to use and well documented to boot.

Olivier Marsden

Very useful!

Eddie Fiorelli

Excellent work, thorough documentation. Thanks!

Mattias Forsblom


Kelvin Rocha

Very useful. Explanations are excellent. Exactly what I was looking for.

Gerald Dalley

Very nice

ke wang

Very Useful and convenient. Easy to use!!

Arnd-Ragnar Rhiemeier

Excellent package. Help topics very comprehensive. Easy to use. Quickly leads to appealing graphical output. This package is exactly what I was looking for.

Bernhard Boeck

That's exactly what I'm looking for

Benedikt Halldorsson

Neat package, but (unless I'm missing something obvious) renders itself essentially USELESS.
Try setting the linestyle of the arrow line to dotted (set(h,'linestyle',':') and then try printing it out to a file (print -depsc test.eps) and view the postscript image. The line certainly is not dotted (on Matlab 6.5). Same problem with dashed and dot-dashed lines.
I'm not sure if this is an arrow.m problem, or Matlab's.

Jakob van de Laar

Great package, it should be incorporated in
the standard Matlab distribution

M Bakht

It is just great. Amazing.

Niclas Borlin


Aslak Grinsted

a c

greatest function ever!

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!