Set Project Path at Startup and Reset at Shutdown

In Simulink® Project, you can view an example startup shortcut file in the Airframe example project that sets the MATLAB® path, and defines where to create the slprj folder. The project also contains a shutdown shortcut to reverse these changes. You can copy and modify these files to set up your own project path.

  1. Open the Airframe project.

    sldemo_slproject_airframe
    
  2. In the Simulink Project, click the Shortcut Management node.

  3. Open set_up_project.m.

  4. In the Editor, observe how the script sets the path for the project.

    % Set the path for this project.
    folders = project_paths();
    for jj=1:numel(folders)
        addpath( fullfile(projectRoot, folders{jj}) );
    end
    

    This code uses the file project_paths to set the path.

  5. In the Simulink Project, open clean_up_project.m.

  6. Observe how this script removes the paths added at startup.

    % Remove paths added for this project. Get the single definition
    % of the folders to add to the path:
    folders = project_paths();
    
    % Remove these from the MATLAB path:
    for jj=1:numel(folders)
        rmpath( fullfile(projectRoot, folders{jj}) );
    end

    This code uses the same file project_paths to define the folders to add and remove from the path in a single place.

  7. In the Simulink Project, select the Project Files view and expand the utilities folder.

  8. Open project_paths.m.

  9. Observe how the file defines a list of folders to add and remove from the path at startup and shutdown.

    folders = { ...
        'batch_jobs', ...
        'data', ...
        'models', ...
        'utilities', ...
        'work' ...
        };

    Edit this list of folders to set up your own project path.

You can use the Project Environment template to add these three shortcut files when you create a new project. Then modify them to set up your path as desired. For details, see Using Templates to Create Standard Project Settings.

Alternatively, copy the files to an existing project, edit them as needed, add them to the project, and set them to run at startup and shutdown.

Related Examples

More About

Was this topic helpful?