Skip to content

Instantly share code, notes, and snippets.

@joeyv120
Created December 12, 2024 14:57
Show Gist options
  • Save joeyv120/c034b1dfd5c0aad242e3c5bbadad524d to your computer and use it in GitHub Desktop.
Save joeyv120/c034b1dfd5c0aad242e3c5bbadad524d to your computer and use it in GitHub Desktop.
MATLAB - Navigating Windows Files and Directories
% Navigate to the folder containing the active editor file
% https://www.mathworks.com/matlabcentral/answers/81148-get-path-from-running-script
cd(fileparts(matlab.desktop.editor.getActiveFilename));
% Navigate to the folder containing the currently running program
% https://www.mathworks.com/matlabcentral/answers/81148-get-path-from-running-script
mfilePath = mfilename('fullpath');
if contains(mfilePath,'LiveEditorEvaluationHelper')
mfilePath = matlab.desktop.editor.getActiveFilename;
end
cd(fileparts(mfilePath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment