Error loading files after compiling an app in AppDesigner

5 views (last 30 days)
I'm testing a very simple app to visualize .nii images (a type of medical image) in slices, developed in AppDesigner. It uses a Callback for a single button to select and show the image, this callback works with a function to process and show the image.
When I run the app into the AppDesigner interface, no errors occur, but after I compile it and test, the compiled app doesn't show the image, as if the function didn't work.
below is the Callback and function code:
% Button pushed function: ShowniiimageButton
function ShowniiimageButtonPushed(app, event)
[file, path] = uigetfile('*.nii');
disp(['User selected ', fullfile(path, file)]);
app.nifti = niftiread(file);
showNifti(app, app.nifti);
end
% function to process the image
% this function was based on another function used in GUIDE, that's why I
% used the convert function
function showNifti (app, handles) %#ok<*INUSD>
[hObject, eventdata, handles] = convertToGUIDECallbackArguments(app); %#ok<*ASGLU>
acquisition = squeeze(app.nifti);
[row, col, z] = size(acquisition);
figure (1)
imagesc(acquisition(:,:,1));
colormap jet;
title('Transverse');
sld = uicontrol('Style', 'Slider', 'SliderStep', [1/90 1], 'Value',1,...
'Min', 1, 'Max', 91, 'Callback', @callbackslider01); %#ok<NASGU>
annotation('textbox',...
[0.01 0.9 0.10 0.10],...
'String',{'Nifti'},...
'FontSize',14,...
'FontName','Arial',...
'LineStyle','--')
function callbackslider01(hObject, eventdata) %solution to work the slider is this nested function
app.val = hObject.Value;
guidata(hObject, app.val);
figure (1);
imagesc(acquisition(:,:,app.val));
title(num2str(app.val));
colormap jet;
end
end
properties (Access = private)
nifti %Image
info %nifti info
val
end

Answers (1)

Steven Lord
Steven Lord on 1 Oct 2021
[file, path] = uigetfile('*.nii');
disp(['User selected ', fullfile(path, file)]);
app.nifti = niftiread(file);
You ask the user to select a file and receive the name of that file and the path to the file.
You display the fullly qualified name of the file, including both the path and the file name.
Then you try to read the file using its name.
The description of that third step looks a bit short. Shouldn't that third step involve the path to the file like the first two steps do? Try using fullfile in that third step like you did in the second.

Categories

Find more on App Building 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!