Skip to content

Commit c965341

Browse files
committed
Added doco and return graphics handle.
1 parent 9536dac commit c965341

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

plot_box.m

+19-8
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@
1616
% specifying a region in terms of top-left coordinate, width and height. One box is
1717
% drawn for each row of BOX which is [xleft ytop width height].
1818
%
19+
%
20+
% H = PLOT_ARROW(...) as above but returns the graphics handle of the arrow.
21+
%
1922
% Options::
20-
% 'edgecolor' the color of the circle's edge, Matlab color spec
21-
% 'fillcolor' the color of the circle's interior, Matlab color spec
23+
% 'edgecolor' the color of the circle's edge, MATLAB ColorSpec
24+
% 'fillcolor' the color of the circle's interior, MATLAB ColorSpec
2225
% 'alpha' transparency of the filled circle: 0=transparent, 1=solid
2326
%
24-
% - For an unfilled box any standard MATLAB LineStyle such as 'r' or 'b---'.
25-
% - For an unfilled box any MATLAB LineProperty options can be given such as 'LineWidth', 2.
27+
% - For an unfilled box:
28+
% - any standard MATLAB LineSpec such as 'r' or 'b---'.
29+
% - any MATLAB LineProperty options can be given such as 'LineWidth', 2.
2630
% - For a filled box any MATLAB PatchProperty options can be given.
2731
%
32+
% Examples::
33+
% plot_box([0 1; 0 2], 'r') % draw a hollow red box
34+
% plot_box([0 1; 0 2], 'fillcolor', 'b', 'alpha', 0.5) % translucent filled blue box
35+
%
2836
% Notes::
2937
% - The box is added to the current plot irrespective of hold status.
30-
% - Additional options LS are MATLAB LineSpec options and are passed to PLOT.
3138
%
3239
% See also PLOT_POLY, PLOT_CIRCLE, PLOT_ELLIPSE.
3340

@@ -54,7 +61,7 @@
5461
%
5562
% https://github.com/petercorke/spatial-math
5663

57-
function plot_box(varargin)
64+
function h = plot_box(varargin)
5865
opt.centre = [];
5966
opt.topleft = [];
6067
opt.matlab = [];
@@ -124,13 +131,17 @@ function plot_box(varargin)
124131

125132
if isempty(opt.fillcolor)
126133
% outline only
127-
plot(x, y, args{:})
134+
hh = plot(x, y, args{:})
128135
else
129136
% filled shape
130-
patch(x, y, 0*y, 'FaceColor', opt.fillcolor, ...
137+
hh = patch(x, y, 0*y, 'FaceColor', opt.fillcolor, ...
131138
'FaceAlpha', opt.alpha, 'EdgeColor', opt.edgecolor, args{:});
132139
end
133140

141+
if nargout > 0
142+
h = hh;
143+
end
144+
134145
if holdon == 0
135146
hold off
136147
end

0 commit comments

Comments
 (0)