windowsmatlabmatlab-guide

shortcut in the windows starting menu - Matlab executable


I create an executable based on a gui with several functions and files, and if I open the executable in the installation folder or using the desktop shortcut everything works fine. If I open through the starting menu, the executable doesn't incorporate the images and doesn’t run. What I can do to prevent this issue? Is it possible to prevent the shortcut in the windows starting menu?


Solution

  • I found a solution here:

    You can use the following function to get the folder of the executed exe file:

    function currentDir = getcurrentdir()
    if isdeployed % Stand-alone mode.
        [status, result] = system('path');
        currentDir = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
    else % MATLAB mode.
        currentDir = pwd;
    end
    

    Call the function and use cd in the GUI opening function:

    currentDir = getcurrentdir();
    cd(currentDir);
    

    I created a guide testing application, and used deploytool for compiling and packaging for external deployment.

    For testing, I added a text label to the GUI (Tag name: text2).

    In the GUI opening function I added the following code:

    % --- Executes just before GuideApp is made visible.
    function GuideApp_OpeningFcn(hObject, eventdata, handles, varargin)
    handles.output = hObject;
    
    handles.text2.String = 'Starting...';
    pause(1);
    currentDir = getcurrentdir();
    
    %Set the label's text to display currentDir.
    handles.text2.String = currentDir;
    
    %Change directory to the directory of the exe file.
    cd(currentDir);
    
    %Create a file in the directory (just for testing):
    f = fopen('currentDir.txt', 'w');fprintf(f, '%s\r\n', currentDir);fclose(f);
    
    % Update handles structure
    guidata(hObject, handles);
    

    The above solution is working correctly:
    The text of label displays the path of the exe file.
    currentDir.txt file is created in the path of the exe file.