Search Comments and Ratings

go

   
Date File Comment by Comment Rating
16 Dec 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Barbara

27 Nov 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Eli

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

19 Nov 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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

...
set(H,oldArrowProps,oldArrowValue);

11 Nov 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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)));

11 Nov 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Justin A.

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

11 Nov 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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);

29 Oct 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Yang Liu

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

21 Oct 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson David

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
'matlab.graphics.axis.Axes'.
Error in arrow (line 423)
ax = o * gca;

24 Sep 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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.

15 Sep 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Pete

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

21 Aug 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Darien

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

22 Jul 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Johan

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,
Johan.

16 Jul 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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);

10 Jul 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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 'matlab.graphics.axis.Axes'.

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

Can somebody please help me?

11 Jun 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Simon Angus

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
d=stop-start;
dx=d(1);dy=d(2);dz=d(3);
[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

04 Mar 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Pegah Hosseini

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

05 Feb 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Yagiz

08 Jan 2014 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Li Zhang

Useful! How to change the color of the arrow ?

17 Oct 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Alan

13 Aug 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson ammar al jodah

11 Jul 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Harish Babu Kankanala

30 May 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Alexandros Iliopoulos

02 May 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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.

30 Mar 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Jan Motl

07 Mar 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Jan Valdman

Perfect!

11 Feb 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Sisi Ma

10 Feb 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Rajib Mozumder

I wrote the following code:

figure(1)
clf
hold on;
scatter3(X,Y,Z,'ko')
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?

20 Jan 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Michael Chan

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

17 Jan 2013 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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.

12 Dec 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Haochen Tang

11 Oct 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Ryan

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.

11 Jun 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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!

30 May 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Felix

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

14 May 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Jiangmin zhang

07 May 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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?

01 Apr 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson ATN

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.

16 Mar 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Yuanye Wang

exactly what I need. thanks a lot.

14 Feb 2012 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Tobias

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];

figure
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!

BW,
Tobi

29 Dec 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson John Colby

Wonderful. Thank you, Erik!!!

21 Dec 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Kuifeng

01 Sep 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Jacopo

> Christopher This code, at least on >R2009a, looks very strange.
>close all; clc;
>figure(1)
>arrow([0;0;0],[1;0;0])
>arrow([0;0;0],[0;1;0])
>arrow([0;0;0],[0;0;1])
>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)

31 Aug 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Will

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];

figure
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.

19 Jul 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson 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!

08 Jul 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Dmytro Lituiev

19 May 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Marco idiart

Perfect. Just what I was needing.

21 Apr 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Zhibo

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!

18 Mar 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Richard Crozier

Really useful, thanks!

18 Mar 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Miguel Gil-Pugliese

Thanks :)

08 Mar 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson Arthur

Very nice, thanks

03 Mar 2011 arrow.m Draw a line with an arrowhead. Author: Erik Johnson guizhi

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

Contact us