function rect(X1,X2,Y1,Y2,C) % rect(X1,X2,Y1,Y2,C) Plot a rectangle at the specified co-ordinates. % Draws a rectangle with vertices (X1,Y1) and (X2,Y2) in color C % (by default, 'r' for red). If the arguments are vectors, % a separate rectangle is drawn taking corresponding elements from % each vector. rect(X) (or rect(X,C) ) will work if X is a four- % column matrix with columns corresponding to X1,X2,Y1,Y2. % dpwe 1994jun30 hold; % overlay on existing plot if(exist('Y1')==0) % assume 1 or 2 arg version if(exist('X2')==1) C = X2; % 2nd arg actually color end end if(exist('C')==0) % no color arg found C = 'r'; end cs = prod(size(C)); if(exist('Y1')==1) % all four elements specified nr = prod(size(X1)); for r = 1:nr cc = C(min(r,cs)); plot([X1(r),X1(r),X2(r),X2(r),X1(r)], [Y1(r),Y2(r),Y2(r),Y1(r),Y1(r)],cc); end else nr = size(X1,1); for r = 1:nr cc = C(min(r,cs)); plot([X1(r,1),X1(r,1),X1(r,2),X1(r,2),X1(r,1)],[X1(r,3),X1(r,4),X1(r,4),X1(r,3),X1(r,3)],cc); end end hold; % i.e. release