MATLAB: Making a rectangle with one mouse click

rectangle fixed size ginput

I work in matlab with a code that was already made by somebody else. In this code you can choose to form a rectangle area with the code ginput, so in my image I click one two spots to form a rectangle and then the code goes further:
if PickRegion==1
fprintf('Pick two corners to indicate the region for tracking \n')
figure(1);
[xreg yreg] = ginput(2); %2 points
if (length(xreg) < 2)
return%break
end
rect=[min(xreg) min(yreg) abs(xreg(2)-xreg(1)) abs(yreg(2)-yreg(1))] %rect:[left low xsize ysize]
end
Now I would like to form the same size rectangle everytime but be able to choose where to place it, so that in different images the size of the rectangle is always the same. So that with one mouse click I can choose for example the upper right corner and then a fixed size rectangle is formed. How should I go about making this code, can anybody help?
Thanks in advance !

Best Answer

I suggest you use rbbox() for creating the first box. Then use ginput(1) to specify the upper left corners of the subsequent boxes.