MATLAB: Imshow in App Designer (Image size doesn’t fit)

app designerimshow

Hey Guys,
the size of imshow in app designer doesn't fit, when I start the application (see picture and code below). Is it possible, that the image have the same size as the UiAxes in app designer?
function startupFcn(app)
imshow('Flower.jpg','parent',app.UIAxes)
end
Thank you very much for your help. Best regards Erdal

Best Answer

Hello,
From my understanding of your question, you wish to display an image which will take up the entire space within the figure in an App Designer app. Consider the following code:
% Fill figure with axes and remove tick labels
app.UIAxes.Position = [0 0 app.UIFigure.Position(3:4)];
% Remove title, axis labels, and tick labels
title(app.UIAxes, []);
xlabel(app.UIAxes, []);
ylabel(app.UIAxes, []);
app.UIAxes.XAxis.TickLabels = {};
app.UIAxes.YAxis.TickLabels = {};
% Display image and stretch to fill axes
I = imshow('Flower.jpg', 'Parent', app.UIAxes, ...
'XData', [1 app.UIAxes.Position(3)], ...
'YData', [1 app.UIAxes.Position(4)]);
% Set limits of axes
app.UIAxes.XLim = [0 I.XData(2)];
app.UIAxes.YLim = [0 I.YData(2)];
This programmatically resizes and repositions the axes to fill the entire figure window. It then removes the axes title as well as the axis labels and tick labels for each axis, allowing the axes to fill the figure as much as possible.
Then, the image is displayed, and instructed to stretch to fill the axes by setting the 'XData' and 'YData' properties.
Finally, the limits of the axes are set so that no additional space is padded around the image.
If, instead of filling the entire figure, you just wish to fill the entire axes with the image, you should be able to just remove the first line.