MATLAB: How to keep figure window maximized when showing an image

figureguiprogrammingwindowwindowapi

I am building a programmatic GUI for an experiment where a test participant will view a series of images, and after each image, respond with a rating for the image.
I want to keep the window maximized, so desktop clutter etc. will not disturb the visual impression. An image will be displayed for a few seconds, then removed, and some sliders will appear for the rating. Next, the sliders will be hidden, and a new image will appear, etc.
What happens is, it starts out fine with the maximized figure window, right until I load an image and display it, using imshow or image command – then the figure window resizes to fit the image. I could maximize it back, but that causes some disturbing motion of the window frame.
How can I keep the window maximized, and display an image at 1:1 ratio (not scaled to fit a maximized window), so one pixel in the image fits no more/less than one "pixel" on screen?
Below is an example of what I have now (using Matlab R2013a):
screenSize = get(0,'screensize');
screenWidth = screenSize(3);
screenHeight = screenSize(4);
% create figure window, keeping it invisible while adding UI controls, etc.
hFig = figure('Name','APP',...
'Numbertitle','off',...
'Position', [0 0 screenWidth screenHeight],...
'WindowStyle','modal',...
'Color',[0.5 0.5 0.5],...
'Toolbar','none',...
'Visible','off');
% make the figure window visible
set(hFig,'Visible','on');
% maximize the figure window, using WindowAPI
WindowAPI(hFig, 'Position', 'work');
% pause (in the full version of this script, this would instead be
% a part where some UI elements are shown and later hidden...
pause(1.0);
% creating a handle for imshow, hiding it for now
img = imread('musik.png');
hImshow = imshow(img);
set(hImshow,'Visible','off');
% Show the image
% This is where Matlab decides to modify the figure window,
% so it fits the image rather than staying maximized.
set(hImshow,'Visible','on');
% How can I display an image in an existing-and-maximized figure
% window, so that the window remains maximized, and the image
% is displayed at actual size (not scaled), so one pixel in the
% image is displayed by one "pixel" on the monitor?
Best regards, Christian

Best Answer

A kind user over at stackoverflow.com helped solve this issue:
In short, here's the solution:
hFig = figure('Name','APP',...
'Numbertitle','off',...
'Position', [0 0 screenWidth screenHeight],...
'WindowStyle','modal',...
'Color',[0.5 0.5 0.5],...
'Toolbar','none');
img = imread('someImage.png');
fpos = get(hFig,'Position')
axOffset = (fpos(3:4)-[size(img,2) size(img,1)])/2;
ha = axes('Parent',hFig,'Units','pixels',...
'Position',[axOffset size(img,2) size(img,1)]);
hImshow = imshow(img,'Parent',ha);
By first creating the figure window, then axes of proper size and position, and then displaying the image with imshow, using the axes as parent, the window resizing is avoided.
Cheers, Christian