MATLAB Answers

How to insert image in MatLab

702 views (last 30 days)
Emily Smith
Emily Smith on 3 Oct 2016
Answered: Dada D on 7 Oct 2021 at 15:46
I want to insert an image at (0,0) on a plot. How would I do this and how can I determine the size? And also do I need to convert the image to a png?
Thanks!

Answers (4)

Jakub Rysanek
Jakub Rysanek on 4 Oct 2016
imread() can import whole bunch of graphical data types, including .jpg and .png. Conversion to .png, as you ask, is not necessary.
img = imread('filename.png');
image(img);
To alter the size/positioning of the image within your figure, you can touch the underlying axes object:
x = 0;
y = 0;
width = 0.5;% measured relative to the figure width
height = 0.5;% measured relative to the figure height
set(gca,'units','normalized','position',[x y width height])


Ilgin Kolgeli
Ilgin Kolgeli on 20 May 2020
img=imread('The_Scream.jpg')

Dada D
Dada D on 7 Oct 2021 at 15:46
x = 0; y = 0; width = 0.5;% measured relative to the figure width height = 0.5;% measured relative to the figure height set(gca,'units','normalized','position',[x y width height])

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by