MATLAB Answers

How can I insert an image in App Designer in Matlab R2017b?

213 views (last 30 days)
I want to put an image (.jpg for example) inside the UIFigure in App Designer. Thanks

  0 Comments

Sign in to comment.

Accepted Answer

ALEJANDRO JAVIER USHINA ERAZO
           % Fill figure with axes "ha" and remove tick labels
             app.ha.Position = [0 0 app.UIFigure.Position(3:4)];
            % Remove title, axis labels, and tick labels
            uistack(app.ha,top);
            title(app.ha, []);
            xlabel(app.ha, []);
            ylabel(app.ha, []);
            app.ha.XAxis.TickLabels = {};
            app.ha.YAxis.TickLabels = {};
            % Display image and stretch to fill axes
            I = imshow('Powerlines.jpg', 'Parent', app.ha,'XData', [1 app.ha.Position(3)],'YData', [1 app.ha.Position(4)]);
            % Set limits of axes
            app.ha.XLim = [0 I.XData(2)];
            app.ha.YLim = [0 I.YData(2)];

I hope it helps you

  3 Comments

Riccardo Branca
Riccardo Branca on 16 Dec 2018
Where should this code be inserted? Could you explain a little more how to use it? thnks I'm new to MATLAB
Irma
Irma on 29 May 2019
I have the same question? I've tried to put this oin startap callback function, but it doesn't work,
rmean
rmean on 27 Dec 2019
Create an Axes (2D). In this example it is named app.ha. Then you can copy this code in the startup function. If you Axes has another name, change the code.

Sign in to comment.

More Answers (1)

Melinda Toth-Zubairi
Melinda Toth-Zubairi on 25 Mar 2019
Starting in R2019a you can use the uiimage function to create an image component in App Designer Apps. See the following post for more information.

  0 Comments

Sign in to comment.