Why can't my standalone desktop app find the path to my support files?

4 次查看(过去 30 天)
I'm currently working on a project where i need to load some data for cross correlation and an image for the UI. Therefore, I created a small test-GUI. When i debug, the code works perfectly fine. I made sure to include the image file in the support files when creating the executable, but I don't know how to access the support files when running the executable. I feel I am making a mistake using 'ctfroot', but I honestly don't know how it works and I can't seem to find somebody with a solution or even the same problem.
function loadPic(app)
graphic = uiimage(app.UIFigure);
graphic.Position = [30, 25, 250, 100];
if isdeployed
imagePath = fullfile(ctfroot, 'picture.png');
else
guiPath = which("Gui_Test");
[thisFilePath, ~, ~] = fileparts(guiPath);
imagePath = fullfile(thisFilePath, 'picture.png');
end
if exist(imagePath, 'file')
graphic.ImageSource = imagePath;
else
uialert(app.UIFigure, ['image not found ', imagePath], 'Error');
end
end
The function is called by the callback function of a button.

回答(1 个)

Mohammad Sami
Mohammad Sami 2025-4-23
编辑:Mohammad Sami 2025-4-23
You can try loading them using relative paths instead of ctfroot. So in case of the image you can try the following
imagePath = 'picture.png';
imageinsubfolder = fullfile('subfolder','picure.png');
Another option is to include these files as "Files installed for your end user" section in the application compiler. Meaning these files are not built inside the standalone exe and are instead in the same folder as exe. You can then easily load them using the base path returned by the pwd function.

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by