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

9 次查看(过去 30 天)
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
end
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
disp(pwd)
addpath([pwd,'/icons/']);
% 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';
end
end
methods (Access = public)
function startupFcn(app)
% Configure image axes
app.ImageAxes.Visible = 'off';
app.ImageAxes.Colormap = gray(256);
axis(app.ImageAxes, 'image');
end
% Construct app
function app = roiApp_example
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
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)
createComponents(app)
I added this folder manually in path and also in the code.
imread('icons/background.png')
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

采纳的回答

Aymeric Ferreira
Aymeric Ferreira 2021-4-8
编辑:Aymeric Ferreira 2021-4-8
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')
end
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'};
else
app.roiBackgroundButton.Icon = imread('icons/background.png');
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by