Why can't my standalone desktop app find the path to my support files?
    2 views (last 30 days)
  
       Show older comments
    
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 Comment
Answers (1)
  Mohammad Sami
      
 on 23 Apr 2025
        
      Edited: Mohammad Sami
      
 on 23 Apr 2025
  
      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.
0 Comments
See Also
Categories
				Find more on File Operations 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!

