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(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 % E-mail: david.legland@inrae.fr 0031 % Created: 2003-12-10 0032 % Copyright 2003-2024 INRA - TPV URPOI - BIA IMASTE 0033 0034 % extract handle of axis to draw on 0035 [ax, varargin] = parseAxisHandle(varargin{:}); 0036 0037 rect = varargin{1}; 0038 varargin(1) = []; 0039 0040 % number of rectangles to draw 0041 n = size(rect, 1); 0042 0043 % save hold state 0044 holdState = ishold(ax); 0045 hold(ax, 'on'); 0046 0047 % display each rectangle 0048 h = zeros(n, 1); 0049 for i = 1:n 0050 % compute vertex corodinates 0051 poly = rectToPolygon(rect(i, :)); 0052 % display resulting polygon 0053 h(i) = drawPolygon(ax, poly, varargin{:}); 0054 end 0055 0056 % restore hold state 0057 if ~holdState 0058 hold(ax, 'off'); 0059 end 0060 0061 % process output 0062 if nargout > 0 0063 varargout = {h}; 0064 end