MATLAB: How to make an axes fill the entire figure window when zooming in

MATLABzoom

I want to make an axes fill the entire figure window when I zoom in.
Whenever I zoom in an image, the axes size is not changed even if my figure window is maximized.

Best Answer

The ResizeFcn property of the figure window allows you to specify the name of a function that is called whenever the figure window is resized. Using this property, it is possible to resize the axis to the size of the figure window so that when you zoom in, the zoomed image completely fills the figure window (note that this might be limited by the aspect ratio). The following is the MATLAB code that creates the figure window and shows the loaded image
% load the image
I = imread('bmp_strangness.jpg');
% Create a figure and show the image
figure(1); clf;
image(I);
set(gcf,'PaperPositionMode', 'auto');
set(gcf, 'ResizeFcn', 'resize_fcn');
resize_fcn
This is the code for the resize function
function resize_fcn
set(gcf,'units','pixels');
set(gca,'units','pixels');
w_pos = get(gcf, 'position');
set(gca, 'position', [0 0 w_pos(3) w_pos(4)]);