- in the Editor right click on the file tab and select "Add ... to Search Path".
- in the Current Folder browser locate the folder, right click and select "Add to Path", browse back to where you want to work.
- call ADDPATH command with an absolute path to that folder.
How to sync the location in the editor with the command screen's pwd
6 次查看(过去 30 天)
显示 更早的评论
I am editing a file in the editor , changing lines, output etc I want to run it, but the command window cannot find the location of the edited file and it cannot run the file, cannot find the file's location. Must I sync the two or can Matlab connect the two file locations somehow?
Is that a rare,n un-standard problem or not? What is the simplest way to sync these to running them in the same Matlab version? This must happen millions of times in every day.. Or must I remember some cd .. commands sequence that I need to type in?
Every time I go to another m-file ? And simply want to run it in the command window. Without any fuss.
Why not auto-sync?
1 个评论
Stephen23
2025-4-12
编辑:Stephen23
2025-4-12
I already explained this in your (almost identical) previous question:
Forget about "syncing", this is not a concept that exists in MATLAB. The actual solution is to add the folder to the Search Path. You can easily add any folder to the Search Path using e.g.:
The Search Path is how you tell MATLAB where to look for code files. Use the Search Path.
回答(1 个)
Steven Lord
2025-4-12
See the "Files and Folders MATLAB Accesses" documentation page for a fuller description, but basically if you want your file to be accessible to MATLAB it generally needs to be in one of two places:
- In the current folder
- In a folder on the MATLAB Search Path
That first documentation page lists the folder whose path is returned by the userpath function as a third place, but that's added to the MATLAB Search Path on startup and so I'm counting it as part of the second bullet.
If you don't want to have to change folder over and over as you work on different files, save them in one or more folders on the search path. [You may be tempted to just put them in a folder under matlabroot, since those folder tend to be on the path automatically, but please don't. Reserve matlabroot and its sub-folders for MathWorks-provided files.]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!