DRAWRECT Draw rectangle on the current axis. drawRect(RECT) draws the rectangles defined by RECT = [X0 Y0 W H]. the four corners of rectangle are then : (X0, Y0), (X0+W, Y0), (X0, Y0+H), (X0+W, Y0+H). RECT = [X0 Y0 W H THETA] also specifies orientation for the rectangle. Theta is given in degrees. If RECT is a N-by-4 or N-by-5 array, several rectangles are drawn. drawRect(..., PARAM, VALUE) Specifies one or several parameters name-value pairs, see plot function for details. drawRect(AX, ...) Specifies the handle of the axis to draw the rectangle on. H = drawRect(...) Returns handle of the created graphic objects. See Also: drawOrientedBox, drawBox, rectToPolygon
0001 function varargout = drawRect(rect, varargin) 0002 %DRAWRECT Draw rectangle on the current axis. 0003 % 0004 % drawRect(RECT) 0005 % draws the rectangles defined by RECT = [X0 Y0 W H]. 0006 % the four corners of rectangle are then : 0007 % (X0, Y0), (X0+W, Y0), (X0, Y0+H), (X0+W, Y0+H). 0008 % 0009 % RECT = [X0 Y0 W H THETA] also specifies orientation for the rectangle. 0010 % Theta is given in degrees. 0011 % 0012 % If RECT is a N-by-4 or N-by-5 array, several rectangles are drawn. 0013 % 0014 % drawRect(..., PARAM, VALUE) 0015 % Specifies one or several parameters name-value pairs, see plot function 0016 % for details. 0017 % 0018 % drawRect(AX, ...) 0019 % Specifies the handle of the axis to draw the rectangle on. 0020 % 0021 % H = drawRect(...) 0022 % Returns handle of the created graphic objects. 0023 % 0024 % See Also: 0025 % drawOrientedBox, drawBox, rectToPolygon 0026 % 0027 0028 % --------- 0029 % author : David Legland 0030 % INRA - TPV URPOI - BIA IMASTE 0031 % created the 10/12/2003. 0032 % 0033 0034 % HISTORY 0035 % 2003-12-12 add support for multiple rectangles 0036 % 2011-10-09 rewrite using rectToPolygon, add support for drawing options 0037 % 2011-10-11 add management of axes handle 0038 0039 % extract handle of axis to draw on 0040 if isAxisHandle(rect) 0041 ax = rect; 0042 rect = varargin{1}; 0043 varargin(1) = []; 0044 else 0045 ax = gca; 0046 end 0047 0048 % number of rectangles to draw 0049 n = size(rect, 1); 0050 0051 % display each rectangle 0052 r = zeros(n, 1); 0053 for i = 1:n 0054 % compute vertex corodinates 0055 poly = rectToPolygon(rect(i, :)); 0056 % display resulting polygon 0057 r(i) = drawPolygon(ax, poly, varargin{:}); 0058 end 0059 0060 % process output 0061 if nargout > 0 0062 varargout = {r}; 0063 end