How to sync Matlab file location and current pwd of command window?

10 views (last 30 days)
My Matlab code sits in a loooong file name folder and my command window just in
>> pwd
ans =
'/Users/uhligfd/matlabin/myREF24'
How can I successfully "run" my code and get answers inside the short name command window. Some syncing of sorts seems needed, but how to sync the two locations?

Answers (1)

Stephen23
Stephen23 on 8 Apr 2025
Edited: Stephen23 on 8 Apr 2025
Do NOT use CD for this.
This is exactly what the MATLAB Search Path is for:
Simply add the folder containing your code to the Search Path (e.g. using ADDPATH) and then you can call it from anywhere, regardless of where your current directory is.
"syncing" directories is not a concept that exists in MATLAB. Use CD from the command line when developing and testing things, but not for actually running your code (it is slow and makes debugging harder).

Categories

Find more on Search Path 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!