Clear Filters
Clear Filters

app not finding image files on some installation (Matlab 2019 problem ?)

6 views (last 30 days)
I developped a visual App for Matlab but the behaviour is different based on different computer.
Here is my code that is working on my computer and on one of my colleague (both Windows 10).
I also join an archive with the images and the script.
classdef roiApp_example < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ImageAxes matlab.ui.control.UIAxes
LoadImageButton matlab.ui.control.Button
projectionDropdown matlab.ui.control.DropDown
roiBackgroundButton matlab.ui.control.Button
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% addpath(genpath([pwd,'/icons/']));
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.AutoResizeChildren = 'off';
app.UIFigure.Position = [100 100 1500 900];
app.UIFigure.Name = 'ROI drawer App';
app.UIFigure.Resize = 'off';
% Create ImageAxes
app.ImageAxes = uiaxes(app.UIFigure);
app.ImageAxes.XTick = [];
app.ImageAxes.XTickLabel = {'[ ]'};
app.ImageAxes.YTick = [];
app.ImageAxes.Position = [1 181 0.45*app.UIFigure.Position(3) 0.45*app.UIFigure.Position(3)];
app.ImageAxes.Interactions = [zoomInteraction, regionZoomInteraction];
% Create LoadButton
app.LoadImageButton = uibutton(app.UIFigure, 'push');
app.LoadImageButton.ButtonPushedFcn = createCallbackFcn(app, @LoadImage, true);
app.LoadImageButton.Position = [20 10 225 22];
app.LoadImageButton.Text = 'Load Tiff stack';
% Create projectionDropdown
app.projectionDropdown = uidropdown(app.UIFigure);
app.projectionDropdown.ValueChangedFcn = createCallbackFcn(app, @ChangeProjection, true);
app.projectionDropdown.Position = [250 10 225 22];
app.projectionDropdown.Items = {'Min', 'Mean', 'Max'};
app.projectionDropdown.Value = 'Max';
% Create Button
app.roiBackgroundButton = uibutton(app.UIFigure, 'push');
app.roiBackgroundButton.Position = [630 60 75 75];
app.roiBackgroundButton.Text = '';
app.roiBackgroundButton.Tooltip = 'Background';
app.roiBackgroundButton.Icon = imread('icons/background.png');
app.roiBackgroundButton.BackgroundColor = '#e6e6e6';
app.roiBackgroundButton.ButtonPushedFcn = createCallbackFcn(app, @add_background_ROI, true);
app.UIFigure.Visible = 'on';
methods (Access = public)
function startupFcn(app)
% Configure image axes
app.ImageAxes.Visible = 'off';
app.ImageAxes.Colormap = gray(256);
axis(app.ImageAxes, 'image');
% Construct app
function app = roiApp_example
% Create UIFigure and components
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
On two others computers I receive this error message
Error using matlab.ui.control.internal.model.mixin.IconableComponent/set.Icon (line 54)
You have specified a file that cannot be found or is not an image.
Specify a file name that is on the MATLAB path, or use a full or relative path.
Error in roiApp_example/createComponents (line 52)
app.roiBackgroundButton.Icon = imread('icons/background.png');
Error in roiApp_example (line 72)
I added this folder manually in path and also in the code.
is working and find the img.
The two working computers are on 2020a, a faulty one is on 2019b but it looks strange if this is the cause of the problem

Accepted Answer

Aymeric Ferreira
Aymeric Ferreira on 8 Apr 2021
Edited: Aymeric Ferreira on 8 Apr 2021
Updating installation Matlab from R2019 to R2021 solved the issue so it was definitively an error depending on Matlab option.
I decided to handle it with a message warning
matlabVersion = version('-release');
matlabVersion = str2num(matlabVersion(1:4));
if matlabVersion < 2020
warning('Matlab version should be 2020 or higher. This version will not show icons')
And then a condition to show text only instead of icon on older Matlab versions
app.roiBackgroundButton.Text = '';
if matlabVersion < 2020
app.roiBackgroundButton.Text = {'Background', 'ROI'};
app.roiBackgroundButton.Icon = imread('icons/background.png');

More Answers (0)


Find more on Develop uifigure-Based Apps in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!