From: Andrew on
Hello,

I am looking to create a figure which can be resized by the user. However, I want there to be a lower limit to this capability. I tried using a method similar to the one below and it seems to work a majority of the time. If the user is resizing from the bottom or from the right, the program quickly resets the figure to the minimum size allowed. The problem arises when the user tries to resize from the left or top. The figure appears to flash repeatedly throughout the resizing process. What I believe is happening is that the resize callback is being called several times while the user is dragging the edge of the figure rather than waiting for the process to be complete. This would not be an issue except that when the user is done resizing, the program does not always return the figure to the appropriate size. I can't seem to find any rhyme or reason as to when it resizes perfectly
and when it fails to do so. I was curious if anybody knew why this was occurring and a possible way to fix it. Thank you.

function figureResize
figure('ResizeFcn',@setMinimum);
end

function setMinimum(hObject,~)
p1 = getpixelposition(hObject);

if p1(3) < 400
set(hObject,'Position',[p1(1:2) 400 p1(4)]);

movegui(hObject,'onscreen');
end

if p1(4) < 300
set(hObject,'Position',[p1(1:3) 300]);

movegui(hObject,'onscreen');
end
end