How do I set a source image inside directory with .ImageSource?

I'm using Matlab App Designer ver. R2025b and I’m having a trouble assigning correct path for my image. Path is “\Assets\_1\rect.png”.
app.I_first.ImageSource="\Assets\_1\rect.png";
I also tried using imread() function to no effect.
img=imread("\Assets\_1\rect.png");
app.I_first.ImageSource=img;
The problem is that it's unable to find this file using this path. Also I’m attaching error messages that gives me while using imread() function.
Error using imread>get_full_filename (line 635)
Unable to find file "\Assets\_1\rect.png".
Error in imread (line 395)
fullname = get_full_filename(filename);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in main/DD_FirstValueChanged (line 337)
img=imread("\Assets\_1\rect.png");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 54)
newCallback = @(source, event)executeCallback(ams, ...
^^^^^^^^^^^^^^^^^^^^^^^^
Error while evaluating DropDown PrivateValueChangedFcn.

 Respuesta aceptada

Richard
Richard el 15 de Jun. de 2026 a las 12:08
baseFolder = fileparts(mfilename("fullpath"));
imgPath = fullfile(baseFolder, "Assets\_2\", "rect.png");
img=imread(imgPath);
app.I_first.ImageSource=img;
This is the solution

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2025b

Preguntada:

el 15 de Jun. de 2026 a las 9:25

Comentada:

el 15 de Jun. de 2026 a las 12:19

Community Treasure Hunt

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

Start Hunting!

Translated by