File Exchange

## Arrow3

version 5.17.1 (414 KB) by Tom Davis

### Tom Davis (view profile)

Updated 13 Feb 2020

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

ARROW3(P1,P2) draws lines from P1 to P2 with directional arrowheads. P1 and P2 are either nx2 or nx3 matrices. Each row of P1 is an initial point, and each row of P2 is a terminal point.

ARROW3(P1,P2,S,W,H,IP,ALPHA,BETA) can be used to specify properties of the line, initial point marker, and arrowhead. Type "help arrow3" at the command prompt for more information

What's new in Version 5:

All arrowhead and initial point marker sizes (W, H, and IP) are relative to the PlotBox diagonal.

Version 5 attempts to preserve the appearance of existing axes. In particular, ARROW3 will not change XYZLim, View, or CameraViewAngle. ARROW3 does not, however, support stretch-to-fill scaling. If a particular aspect ratio or variable limit is required, use DASPECT, PBASPECT, AXIS, or XYZLIM commands before calling ARROW3. Users are encouraged to report problems directly to the author.

### Cite As

Tom Davis (2020). Arrow3 (https://www.mathworks.com/matlabcentral/fileexchange/14056-arrow3), MATLAB Central File Exchange. Retrieved .

Tom Davis

### Tom Davis (view profile)

Hello, Allen --
As documented in the Overview above, and consistent with PLOT3, "P1 and P2 are either nx2 or nx3 matrices. Each row of P1 is an initial point, and each row of P2 is a terminal point." If column vectors are more convenient, you can transpose them, e.g. arrow3([0;0;0]',[1;1;1]').

Alan Peters

### Alan Peters (view profile)

This only works if the start and end vectors are rows (1x3). Given 2 column vectors, it returns 'Invalid input, type HELP ARROW3 for usage examples '

Tom Davis

### Tom Davis (view profile)

Hello, Chris --
Version 5.17 does not adequately address the line color issue. I will post an interim fix that I hope will meet most needs, but the code still has a lot of problems. Arrow3 makes extensive use of the ColorOrder property, and that property has changed fundamentally in 2019b.

Chris Jennings

### Chris Jennings (view profile)

I've been using arrow3 for some time, but suddenly I cannot control line colors. For example:
used to produce light grey arrows, but now they are blue.
(Also happens for my older scripts that used to work fine)
I'm using MATLAB 2019b
Is anyone else experiencing this?

Christian Krogh

Tom Davis

### Tom Davis (view profile)

Hello, Li --
It is most likely that the problem is the position of the last line of code. From the Overview above, "If a particular aspect ratio or variable limit is required, use DASPECT, PBASPECT, AXIS, or XYZLIM commands before calling ARROW3." See also arrow3_messes_up_my_plots.html in arrow3.zip.

Tom Davis

### Tom Davis (view profile)

Hello, Li --
I do not have wind.dat. Please contact me through my MathWorks profile, and we'll sort it out.

li linjiang

### li linjiang (view profile)

First, I use quiver to get P1 and P2 of the arrows. Then I use Arrow3 to draw the arrows. I found that the base of the head is not perpendicular to the line. Can you please help me to solve this. My code is as follows:
x=data(:,1);
y=data(:,2);
u =data(:,3);
v =data(:,4);

%// Taken from "quiver.m". Computes autoscale
if min(size(x))==1, n=sqrt(numel(x)); m=n; else [m,n]=size(x); end
delx = diff([min(x(:)) max(x(:))])/n;
dely = diff([min(y(:)) max(y(:))])/m;
del = delx.^2 + dely.^2;
if del>0
len = sqrt((u.^2 + v.^2)/del);
maxlen = max(len(:));
else
maxlen = 0;
end
if maxlen>0
autoscale = 0.9 / maxlen;
else
autoscale = 0.9;
end

%// quiver plot
quiver(x, y, u, v)
p1=[x,y];
m=autoscale*u;
n=autoscale*v;
arrow3(p1,p1+[m,n],'k',0.18,1.5)
axis([1 28 -1.5 1.5]), daspect([8 2 1])

Valdelirio

### Valdelirio (view profile)

Debasis Mohapatra

Tom Davis

### Tom Davis (view profile)

Version 5.17 addresses line color issues introduced in R2019b.

Cuneyt Aydin

Tom Davis

### Tom Davis (view profile)

Thank you for the bug report, David.

There is no intentional mechanism to set arrowhead color independent of line color. I believe the line color issue is related to new color and line style features in R2019b. I have made preliminary changes to the code that support single-colored lines and arrows, e.g. your example, but multicolored lines and arrows are still a problem. See arrow3_examples.html and attendant images in arrow3.zip for examples of intended results.

Contact me through my MathWorks profile, and I will keep you updated as I modify Arrow3.

Cuneyt Aydin

David Brinkmeier

### David Brinkmeier (view profile)

Matlab r2019b: Color specification has no effect on line color
source code indicates line color using plot3 is not set whatsoever - why would I want to set the arrowhead color independent of the line?

ex.
arrow3(-eye(3),eye(3),'k',1.25,[],0)

yields 3 unit vectors with black arrow heads and blue lines for me, plot3 uses the default color order which I don't want to modify globally

Tom Davis

### Tom Davis (view profile)

Hello, Ali --
ALPHA (default = 1) is a vector of FaceAlpha values ranging between 0 (clear) and 1 (opaque). The number of pixels (resolution) does not change with decreasing ALPHA, but the pixels themselves become more transparent.

Ali Aghaeifar

### Ali Aghaeifar (view profile)

Changing "ALPHA" decreases the resolution of arrows. Why?

Ali Aghaeifar

Tom Davis

### Tom Davis (view profile)

Hello, J.P. --
The column vector of decimal values *is* a vector of handles. See comment on 26 Jul 2011 below, re animation.

J. P.

### J. P. (view profile)

How do you remove arrow3 objects from a figure during a looped animation? For some reason hn = arrow3(p1,p2,...) does not return a vector of handles to line and surface objects. In fact, hn is simply a column vector of decimal values. Any help would be greatly appreciated.

Saurabh Patel

### Saurabh Patel (view profile)

Yoganandam Vivekanandham Pushpalatha

Tom Davis

### Tom Davis (view profile)

Hello, Mike --
Arrow3 is 17 years old; it is a testament to MATLAB's backward compatibility that it works at all. Arrow3 always plots to the current figure (gcf) and axis (gca), but it is likely that you can change this behavior by modifying line 349: fig=gcf; ax=gca;

Mike Potter

### Mike Potter (view profile)

How do you cause the arrow3 to draw to a particular axis handle? I'm trying to use it in a GUI (a UIaxes), but the function doesn't seem to allow you to direct it to a particular axes. And the command 'axes(...)' doesn't work with UI axis

Roberto Noriega

Bahram Khazaei

### Bahram Khazaei (view profile)

Is there an easy way to specify which axis to plot the arrows to? I am trying to use in the a matlab app and the axis must be specified.

Renwen Lin

### Renwen Lin (view profile)

It is great. However. the quality of its emf file is low. BTW: I outport the emf file by "save as".

Ricardo Vega Ayora

Jose Ercolino

LMS

### LMS (view profile)

Great function, works perfectly for me.
How do I handle this in the legend, though? I have
eq=arrow3(... first set of arrows
lq=arrow3(... second set of arrows
legend([eq lq],'normals from edges','normals from layers')
and it's giving me an error ("Operands to the || and && operators must be convertible to logical scalar values.")

ritwik chattaraj

yong geng

### yong geng (view profile)

You're so nice guy~

Subhash Pidaparthi

Thank you Tom

Tom Davis

### Tom Davis (view profile)

Hello, Ikem --

Extract the arrow3.zip files to a folder, e.g. C:\arrow3.

Then in the MATLAB Command Window:

cd C:\arrow3
help arrow3

Ikem Solomon

### Ikem Solomon (view profile)

Please how do I install it. I am having problems attaching it to my matlab

Tom Davis

### Tom Davis (view profile)

Hello, John --

This works for me:

image(X)
colormap(map)
axis image
hold on
arrow3([235 215],[130 465],'r-2.5',1.5)
hold off

John Peter Davalos

### John Peter Davalos (view profile)

Arrow head not showing if plotted over an image?

Gopal Karemore

Thank you Tom!

Liya Wang

### Liya Wang (view profile)

Hello Tom,

Sorry I make a mistake.I mixes up lon and lat.I can draw arrows on worldmap now.You can ignore my question earlier.Thank u very much!

Best wishes.

Liya

Liya Wang

### Liya Wang (view profile)

Hello Tom,
Thank you for your answer.When I draw 2D arrows,which plotting functions in your code make it work? I just find plot3.Could you please tell me all plotting functions you used in your code .
--Liya

Tom Davis

### Tom Davis (view profile)

Hello, Liya --

I have neither the Mapping Toolbox nor a recent version of MATLAB. If you can ask specific questions, I may be able to help.

Good luck and best wishes.

-- Tom

Liya Wang

### Liya Wang (view profile)

hello Tom,I want to ask you a question.When I use the function worldmap and draw arrows on it,I try to modify your code,but I can't.Could you please modify your code so that it can be used on the worldmap.Thank u so much!

Le

### Le (view profile)

Thanks a lot! The function is very useful

Nice, saved me from a lot of footwork.

tao song

### tao song (view profile)

I love this .m file.

Andreas J.

### Andreas J. (view profile)

sorry i didn't want to submit the last voting. I didn't read the "relative to the PlotBox diagonal" at the time i was about to write a critic, but as i reread the description i closed the tab.

But i still think that this is an annoying feature, i would like it more if i could choose wether it should be relative or a fix size. I also don't like that it clears the axes. I know a workaround but it's still annoying me everytime i have to use arrow3. Just my opinion.

Andreas J.

Daniel Frisch

yang yang

Ben

### Ben (view profile)

Great code. Have been using it for quite a long time.

Ben

Matthew

Tom Davis

Hi, Jonas --

-- Tom

Jonas

### Jonas (view profile)

I've downloaded arrow3 sometime in 2002 for the first time; great job, guys!

In order to avoid possible conflicts with other code writing to the 'UserData' property, I suggest replacing these calls by "setappdata(ax,'arrow3',value)"

Ji?í

### Ji?í (view profile)

It does not ignore zero magnitue input (R2012a).

>> arrow3([1 1],[1 1])
Error using arrow3 (line 373)
P1 cannot equal P2

Jeonghyun Seo

Xilu Wang

Thanks!!!

Daniel

### Daniel (view profile)

Hi Tom,

thanks for that nice contribution. I would enjoy if you could modify the input arguments with string propertys (similar to most of the inbuilt-functions (f.e. 'LineWidth', 2)), in particular to add a 'Parent' property to get rid of the problems with multiple axes!

Thanks,
Daniel

Tom Davis

### Tom Davis (view profile)

Hello, Tomazc --

Please try this and write if you have questions. Thanks.

% Animation Example
figure(5)
t=(0:pi/40:8*pi)'; u=cos(t); v=sin(t);
plot3(20*t,u,v)
axis([0,600,-1.5,1.5,-1.5,1.5])
grid on, view(35,25)
hold on
pbaspect([1.8,1.4,1])
arrow3(zeros(3),diag([500,1.5,1.5]),'l',0.7,[],0)
p=[20*t,u,v]; inc=4:1:length(t);
p2=p(inc,:); p1=p(inc-1,:);
hn=arrow3(p1(1,:),p2(1,:),'0_b',0.7);
for i=2:1:length(p1)
delete(hn)
hn=arrow3(p1(i,:),p2(i,:),'0_b',0.7);
pause(0.01)
end
hold off

solo

Tomazc

### Tomazc (view profile)

I'd like to use arrow3 in animation (for function) where only one arrow will be shown, so i cannot use 'hold on'.
In this case the 'axis' are not working, but i need the same view.

Any suggestion?

figure('Name',['Arrow'])
axis([-400 400 -400 400 -100 700])
XLABEL('x')
YLABEL('y')
ZLABEL('z')
whitebg([1 1 1]);
set(gcf,'Color',[1,1,1]);
view(35, 25)
grid on

for i = 1:1:15
arrow3([x(i),y(i),z(i)],[fx(i),f(i),fz(i)]);
pause(0.1)
end

Sauro Salomoni

### Sauro Salomoni (view profile)

Does what it's supposed to do, and the help files are VERY detailed. Thank you very much! :)

Gabriel Akira Schreiber

### Gabriel Akira Schreiber (view profile)

Gabriel Akira Schreiber

Tom Davis

### Tom Davis (view profile)

Instead of using Copy Figure from the Edit menu, use Save As from the File menu, save the figure as a PNG file, and then insert the PNG file into Word.

Lei Shang

### Lei Shang (view profile)

Very useful with 3D plots. But when I'm copying figures to word, all the nice arrows plotted by 'arrow3.m' disappeared. And my command window displays:

Warning: RGB CData not yet supported in Painter's mode
> In graphics\private\restorehg at 100
In graphics\private\restore at 29
In print at 277

How do I fix this?

Lei Shang

Tom Davis

### Tom Davis (view profile)

Wide lines may obscure the arrowhead tip, but the line endpoint and arrowhead tip are _always_ coincident.

Philipp Wissgott

### Philipp Wissgott (view profile)

On my matlab (R2007a) the line of the arrow is visible after the tip of the arrowhead in 2D plots. It looks like as if the arrowhead is plotted at the wrong position.
In my example arrow3 is called after some calls of "line()" and "rectangle()". I can supply further information if required.

Tom Davis

### Tom Davis (view profile)

It is not necessary to set AXIS EQUAL, but commands that may change the aspect ratio should be issued _before_ calling ARROW3. ARROW3 draws surfaces that look like right circular cones and spheres no matter the aspect ratio, but the ratio must be fixed, and changing the ratio will distort the surfaces.

There are many examples in the HTML files that illustrate how to use ARROW3 before and after PLOT, POLAR, CONTOUR, PLOT3, SURF, SLICE, and PATCH.

piao lin

### piao lin (view profile)

it seems if I want to plot another plot3(......) with arrow3(.....)

I should

figure,arrow3(.....);
hold on;
axis equal ; %you'd better use axis equal
plot3(....);

if I put plot3(....) before arrow3(.....) ,just like below ,I get not see the result of arrow3(.....);

figure,plot3(....);
hold on;
axis equal ; %you'd better use axis equal
arrow3(.....);

Vaibhav Deshpande

### Vaibhav Deshpande (view profile)

I am doing a project in layup optimization of balanced symmetric laminates, and I wanted to display at each call to fmincon the material direction for my laminate, I was able to so by using arrow3, thank you.

Regards,
Vaibhav Deshpande.

Georg Stillfried

works fine

dong ding

it's excellent.I can use it to draw my picture. thanks!

Ahmet Sacan

I was happily using arrow.m until I came to see that it for some reason did not draw anything when my m file was deployed (i.e., running executable that resulted from mcc). I came back to File Exchange for a different arrower instead of trying to debug arrow.m. Now I'm using arrow3 which works fine in deployed mode. thanks.

maricel miguel

I havent tried it but looks good from the screen shot, what was the thought process on this one, and how long did it took you