Rank: 102 based on 668 downloads (last 30 days) and 1 file submitted
photo

Erik Johnson

E-mail
Company/University
Univ of Southern California

Personal Profile:

Associate Professor & Associate Chair, Astani Department of Civil & Env. Engineering, University of Southern California
B.S. (1988), M.S. (1993), Ph.D. (1997), Aeronautical & Astronautical Engineering, University of Illinois at Urbana-Champaign
http://www.usc.edu/dept/civil_eng/johnsone/

Professional Interests:

 

Watch this Author's files

 

Files Posted by Erik
Updated   File Tags Downloads
(last 30 days)
Comments Rating
20 May 2009 Screenshot arrow.m Draw a line with an arrowhead. Author: Erik Johnson annotation, customization, arrow, arrowhead, line, graphics 668 86
  • 4.59341
4.6 | 94 ratings
Comments and Ratings by Erik View all
Updated File Comments Rating
12 Jul 2012 legendflex: a more flexible legend Create a legend with more flexible positioning and labeling capabilities Author: Kelly Kearney

If legendflex is called like:

[legend_h, object_h, plot_h, text_str] = legendflex(h, strs, 'ncol', ncols, ... );

then a workaround for the column offset is:

% fix legendflex's subsequent column locations
h = findobj(object_h, 'type', 'line');
y = get(h, {'YData'});
y = repmat(ans(1:ceil(length(y)/2/ncols)*2,:), ncols, 1);
y = ans(1:length(h),:);
set(h, {'YData'}, y);

11 Jul 2012 legendflex: a more flexible legend Create a legend with more flexible positioning and labeling capabilities Author: Kelly Kearney

A VERY useful function. However, I get slight offsets in the vertical locations of the lines/markers in different columns. Have you seen this?

For example, the code:

nrows = 1;
ncols = 3;
n = nrows * ncols;
x = repmat([0;1], 1, n);
y = [zeros(1,n); (1:n)/n];
h = plot(x, y);
strs = num2cell(char('`'+(1:n)), 1)';
[legax,legh] = legendflex(h, strs, 'ncol', ncols);

get(findobj(legh,'type','line','LineStyle','-'),{'YData'});
cat(1,ans{:}); yline=reshape(ans(:,1),[],3)
get(findobj(legh,'type','line','LineStyle','none'),{'YData'});
cat(1,ans{:}); ymarker=reshape(ans(:,1),[],3)
get(findobj(legh,'type','text'),{'Position'});
cat(1,ans{:}); ytext=reshape(ans(:,2),[],3)

gives the results:

yline = [9.5388 9.2710 9.0032]
ymarker = [9.5388 9.2710 9.0032]
ytext = [4.3091 4.3091 4.3091]

showing that the text items are set at consistent locations, but the lines and markers are slightly offset. (Change nrows to, say, 8 and the same vertical offset happens on all elements of subsequent columns.)

Any suggestions?

P.S. This is in MATLAB 7.14.0.739 (R2012a) on a Mac.

Comments and Ratings on Erik's Files View all
Updated File Comment by Comments Rating
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 Caday, Peter

@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 Gram, Tobias Benjamin

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 Angus, Simon

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 Hosseini, Pegah

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

Contact us